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,6 +59,12 @@ describe('Stack', () => {
59 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 68
   it('unmount is called on pop', async () => {
63 69
     await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
64 70
     await elementById(TestIDs.POP_BTN).tap();

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

@@ -14,7 +14,7 @@
14 14
 }
15 15
 
16 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 18
         [self sendScreenPoppedEvent:_presentedViewController];
19 19
     }
20 20
     

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

@@ -6,6 +6,7 @@ const Screens = require('./Screens');
6 6
 const {
7 7
   PUSH_TO_TEST_DID_DISAPPEAR_BTN,
8 8
   DISMISS_MODAL_BTN,
9
+  SCREEN_POPPED_BTN,
9 10
   POP_BTN
10 11
 } = require('../testIDs');
11 12
 
@@ -25,6 +26,7 @@ class LifecycleScreen extends React.Component {
25 26
 
26 27
   constructor(props) {
27 28
     super(props);
29
+    this.showUnmountAndDisappearAlerts = true;
28 30
     Navigation.events().bindComponent(this);
29 31
   }
30 32
 
@@ -33,12 +35,12 @@ class LifecycleScreen extends React.Component {
33 35
   }
34 36
 
35 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 41
   componentWillUnmount() {
40 42
     setTimeout(() => {
41
-      alert('componentWillUnmount'); // eslint-disable-line no-alert
43
+      this.showUnmountAndDisappearAlerts && alert('componentWillUnmount'); // eslint-disable-line no-alert
42 44
     }, 100); 
43 45
   }
44 46
 
@@ -50,6 +52,7 @@ class LifecycleScreen extends React.Component {
50 52
     return (
51 53
       <Root componentId={this.props.componentId} footer={this.state.text}>
52 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 56
         {this.renderCloseButton()}
54 57
       </Root>
55 58
     );
@@ -60,6 +63,14 @@ class LifecycleScreen extends React.Component {
60 63
         <Button label='Pop' testID={POP_BTN} onPress={this.pop} />;
61 64
 
62 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 74
   pop = () => Navigation.pop(this);
64 75
   dismiss = () => Navigation.dismissModal(this);
65 76
 }

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

@@ -102,6 +102,7 @@ module.exports = {
102 102
   PUSH_CONTEXT_SCREEN_BUTTON: `PUSH_CONTEXT_SCREEN_BUTTON`,
103 103
   PUSH_OPTIONS_BUTTON: `PUSH_OPTIONS_BUTTON`,
104 104
   PUSH_DEFAULT_OPTIONS_BUTTON: `PUSH_DEFAULT_OPTIONS_BUTTON`,
105
+  SCREEN_POPPED_BTN: 'SCREEN_POPPED_BTN',
105 106
   SHOW_REDBOX_BUTTON: `SHOW_REDBOX_BUTTON`,
106 107
   ORIENTATION_BTN: `ORIENTATION_BUTTON`,
107 108
   PROVIDED_ID: `PROVIDED_ID`,