Browse Source

Add screenPopped e2e (#6163)

* Add screenPopped e2e

* empty commit

* Fix popped screen event on iOS

* fix e2e on iOS

Co-authored-by: yogevbd <yogev132@gmail.com>
Guy Carmeli 4 years ago
parent
commit
2f31a2fa70
No account linked to committer's email address

+ 6
- 0
e2e/Stack.test.js View File

59
     await expect(elementByLabel('didDisappear')).toBeVisible();
59
     await expect(elementByLabel('didDisappear')).toBeVisible();
60
   });
60
   });
61
 
61
 
62
+  it('Screen popped event', async () => {
63
+    await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
64
+    await elementById(TestIDs.SCREEN_POPPED_BTN).tap();
65
+    await expect(elementByLabel('Screen popped event')).toBeVisible();
66
+  });
67
+
62
   it('unmount is called on pop', async () => {
68
   it('unmount is called on pop', async () => {
63
     await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
69
     await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
64
     await elementById(TestIDs.POP_BTN).tap();
70
     await elementById(TestIDs.POP_BTN).tap();

+ 1
- 1
lib/ios/StackControllerDelegate.m View File

14
 }
14
 }
15
 
15
 
16
 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
16
 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
17
-    if ([navigationController.viewControllers indexOfObject:_presentedViewController] < 0) {
17
+    if (_presentedViewController && ![navigationController.viewControllers containsObject:_presentedViewController]) {
18
         [self sendScreenPoppedEvent:_presentedViewController];
18
         [self sendScreenPoppedEvent:_presentedViewController];
19
     }
19
     }
20
     
20
     

+ 13
- 2
playground/src/screens/LifecycleScreen.js View File

6
 const {
6
 const {
7
   PUSH_TO_TEST_DID_DISAPPEAR_BTN,
7
   PUSH_TO_TEST_DID_DISAPPEAR_BTN,
8
   DISMISS_MODAL_BTN,
8
   DISMISS_MODAL_BTN,
9
+  SCREEN_POPPED_BTN,
9
   POP_BTN
10
   POP_BTN
10
 } = require('../testIDs');
11
 } = require('../testIDs');
11
 
12
 
25
 
26
 
26
   constructor(props) {
27
   constructor(props) {
27
     super(props);
28
     super(props);
29
+    this.showUnmountAndDisappearAlerts = true;
28
     Navigation.events().bindComponent(this);
30
     Navigation.events().bindComponent(this);
29
   }
31
   }
30
 
32
 
33
   }
35
   }
34
 
36
 
35
   componentDidDisappear() {
37
   componentDidDisappear() {
36
-    alert('didDisappear'); // eslint-disable-line no-alert
38
+    this.showUnmountAndDisappearAlerts && alert('didDisappear'); // eslint-disable-line no-alert
37
   }
39
   }
38
 
40
 
39
   componentWillUnmount() {
41
   componentWillUnmount() {
40
     setTimeout(() => {
42
     setTimeout(() => {
41
-      alert('componentWillUnmount'); // eslint-disable-line no-alert
43
+      this.showUnmountAndDisappearAlerts && alert('componentWillUnmount'); // eslint-disable-line no-alert
42
     }, 100); 
44
     }, 100); 
43
   }
45
   }
44
 
46
 
50
     return (
52
     return (
51
       <Root componentId={this.props.componentId} footer={this.state.text}>
53
       <Root componentId={this.props.componentId} footer={this.state.text}>
52
         <Button label='Push to test didDisappear' testID={PUSH_TO_TEST_DID_DISAPPEAR_BTN} onPress={this.push} />
54
         <Button label='Push to test didDisappear' testID={PUSH_TO_TEST_DID_DISAPPEAR_BTN} onPress={this.push} />
55
+        {!this.props.isModal && <Button label='Screen popped events' testID={SCREEN_POPPED_BTN} onPress={this.screenPoppedEvent} />}
53
         {this.renderCloseButton()}
56
         {this.renderCloseButton()}
54
       </Root>
57
       </Root>
55
     );
58
     );
60
         <Button label='Pop' testID={POP_BTN} onPress={this.pop} />;
63
         <Button label='Pop' testID={POP_BTN} onPress={this.pop} />;
61
 
64
 
62
   push = () => Navigation.push(this, Screens.Pushed);
65
   push = () => Navigation.push(this, Screens.Pushed);
66
+  screenPoppedEvent = async () => {
67
+    this.showUnmountAndDisappearAlerts = false;
68
+    const unregister = Navigation.events().registerScreenPoppedListener((event) => {
69
+      alert('Screen popped event')
70
+      unregister.remove();
71
+    });
72
+    await Navigation.pop(this);
73
+  }
63
   pop = () => Navigation.pop(this);
74
   pop = () => Navigation.pop(this);
64
   dismiss = () => Navigation.dismissModal(this);
75
   dismiss = () => Navigation.dismissModal(this);
65
 }
76
 }

+ 1
- 0
playground/src/testIDs.js View File

102
   PUSH_CONTEXT_SCREEN_BUTTON: `PUSH_CONTEXT_SCREEN_BUTTON`,
102
   PUSH_CONTEXT_SCREEN_BUTTON: `PUSH_CONTEXT_SCREEN_BUTTON`,
103
   PUSH_OPTIONS_BUTTON: `PUSH_OPTIONS_BUTTON`,
103
   PUSH_OPTIONS_BUTTON: `PUSH_OPTIONS_BUTTON`,
104
   PUSH_DEFAULT_OPTIONS_BUTTON: `PUSH_DEFAULT_OPTIONS_BUTTON`,
104
   PUSH_DEFAULT_OPTIONS_BUTTON: `PUSH_DEFAULT_OPTIONS_BUTTON`,
105
+  SCREEN_POPPED_BTN: 'SCREEN_POPPED_BTN',
105
   SHOW_REDBOX_BUTTON: `SHOW_REDBOX_BUTTON`,
106
   SHOW_REDBOX_BUTTON: `SHOW_REDBOX_BUTTON`,
106
   ORIENTATION_BTN: `ORIENTATION_BUTTON`,
107
   ORIENTATION_BTN: `ORIENTATION_BUTTON`,
107
   PROVIDED_ID: `PROVIDED_ID`,
108
   PROVIDED_ID: `PROVIDED_ID`,