Browse Source

lifecycle screen fix

Daniel Zlotin 7 years ago
parent
commit
29cb8a4f66

+ 18
- 5
playground/e2e/app.test.js View File

@@ -20,11 +20,19 @@ describe('app', () => {
20 20
   });
21 21
 
22 22
   it('screen lifecycle', () => {
23
-    elementByLabel('Switch to lifecycle screen').tap();
23
+    elementByLabel('Push lifecycle screen').tap();
24 24
     expect(elementByLabel('onStart!')).toBeVisible();
25 25
     elementByLabel('Push to test onStop').tap();
26 26
     expect(elementByLabel('Alert')).toBeVisible();
27
-    expect(elementByLabel('onStop!')).toBeVisible();
27
+    expect(elementByLabel('onStop')).toBeVisible();
28
+  });
29
+
30
+  it('unmount is called on pop', () => {
31
+    elementByLabel('Push lifecycle screen').tap();
32
+    expect(elementByLabel('onStart!')).toBeVisible();
33
+    element(by.traits(['button']).and(by.label('Back'))).tap();
34
+    expect(elementByLabel('onStop')).toBeVisible();
35
+    expect(elementByLabel('componentWillUnmount')).toBeVisible();
28 36
   });
29 37
 });
30 38
 
@@ -148,12 +156,17 @@ describe('modal', () => {
148 156
   });
149 157
 });
150 158
 
151
-describe('reload app', () => {
152
-  before((done) => {
159
+describe.only('reload app', () => {
160
+  beforeEach((done) => {
153 161
     simulator.reloadReactNativeApp(done);
154 162
   });
155 163
 
156
-  it('shows welcome screen', () => {
164
+  it('push a screen to ensure its not there after reload', () => {
165
+    elementByLabel('Push').tap();
166
+    expect(elementByLabel('Pushed Screen')).toBeVisible();
167
+  });
168
+
169
+  it('show welcome screen after reload', () => {
157 170
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
158 171
   });
159 172
 });

+ 1
- 0
playground/scripts/e2e.ios.js View File

@@ -44,6 +44,7 @@ function e2e() { //eslint-disable-line
44 44
                               ./node_modules/mocha/bin/mocha e2e
45 45
                                 --timeout ${10 * 60 * 1000}
46 46
                                 --recursive
47
+                                --bail
47 48
                                 --compilers js:babel-register`);
48 49
   } finally {
49 50
     shellUtils.exec.kill(`detox-server`);

+ 5
- 1
playground/src/containers/LifecycleScreen.js View File

@@ -17,7 +17,11 @@ class LifecycleScreen extends Component {
17 17
   }
18 18
 
19 19
   onStop() {
20
-    alert('onStop!'); //eslint-disable-line
20
+    alert('onStop'); //eslint-disable-line
21
+  }
22
+
23
+  componentWillUnmount() {
24
+    alert('componentWillUnmount'); //eslint-disable-line
21 25
   }
22 26
 
23 27
   render() {

+ 4
- 5
playground/src/containers/WelcomeScreen.js View File

@@ -8,6 +8,7 @@ class WelcomeScreen extends Component {
8 8
     super(props);
9 9
     this.onClickPush = this.onClickPush.bind(this);
10 10
     this.onClickShowModal = this.onClickShowModal.bind(this);
11
+    this.onClickLifecycleScreen = this.onClickLifecycleScreen.bind(this);
11 12
   }
12 13
 
13 14
   render() {
@@ -16,7 +17,7 @@ class WelcomeScreen extends Component {
16 17
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
17 18
         <Button title="Switch to tab based app" onPress={this.onClickSwitchToTabs} />
18 19
         <Button title="Switch to app with side menus" onPress={this.onClickSwitchToSideMenus} />
19
-        <Button title="Switch to lifecycle screen" onPress={this.onClickLifecycleScreen} />
20
+        <Button title="Push lifecycle screen" onPress={this.onClickLifecycleScreen} />
20 21
         <Button title="Push" onPress={this.onClickPush} />
21 22
         <Button title="Show Modal" onPress={this.onClickShowModal} />
22 23
         <Button title="Show Redbox" onPress={this.onClickShowRedbox} />
@@ -105,10 +106,8 @@ class WelcomeScreen extends Component {
105 106
   }
106 107
 
107 108
   onClickLifecycleScreen() {
108
-    Navigation.setRoot({
109
-      container: {
110
-        name: 'navigation.playground.LifecycleScreen'
111
-      }
109
+    Navigation.on(this.props.id).push({
110
+      name: 'navigation.playground.LifecycleScreen'
112 111
     });
113 112
   }
114 113