ソースを参照

lifecycle screen fix

Daniel Zlotin 8 年 前
コミット
29cb8a4f66
共有4 個のファイルを変更した28 個の追加11 個の削除を含む
  1. 18
    5
      playground/e2e/app.test.js
  2. 1
    0
      playground/scripts/e2e.ios.js
  3. 5
    1
      playground/src/containers/LifecycleScreen.js
  4. 4
    5
      playground/src/containers/WelcomeScreen.js

+ 18
- 5
playground/e2e/app.test.js ファイルの表示

20
   });
20
   });
21
 
21
 
22
   it('screen lifecycle', () => {
22
   it('screen lifecycle', () => {
23
-    elementByLabel('Switch to lifecycle screen').tap();
23
+    elementByLabel('Push lifecycle screen').tap();
24
     expect(elementByLabel('onStart!')).toBeVisible();
24
     expect(elementByLabel('onStart!')).toBeVisible();
25
     elementByLabel('Push to test onStop').tap();
25
     elementByLabel('Push to test onStop').tap();
26
     expect(elementByLabel('Alert')).toBeVisible();
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
   });
156
   });
149
 });
157
 });
150
 
158
 
151
-describe('reload app', () => {
152
-  before((done) => {
159
+describe.only('reload app', () => {
160
+  beforeEach((done) => {
153
     simulator.reloadReactNativeApp(done);
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
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
170
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
158
   });
171
   });
159
 });
172
 });

+ 1
- 0
playground/scripts/e2e.ios.js ファイルの表示

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

+ 5
- 1
playground/src/containers/LifecycleScreen.js ファイルの表示

17
   }
17
   }
18
 
18
 
19
   onStop() {
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
   render() {
27
   render() {

+ 4
- 5
playground/src/containers/WelcomeScreen.js ファイルの表示

8
     super(props);
8
     super(props);
9
     this.onClickPush = this.onClickPush.bind(this);
9
     this.onClickPush = this.onClickPush.bind(this);
10
     this.onClickShowModal = this.onClickShowModal.bind(this);
10
     this.onClickShowModal = this.onClickShowModal.bind(this);
11
+    this.onClickLifecycleScreen = this.onClickLifecycleScreen.bind(this);
11
   }
12
   }
12
 
13
 
13
   render() {
14
   render() {
16
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
17
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
17
         <Button title="Switch to tab based app" onPress={this.onClickSwitchToTabs} />
18
         <Button title="Switch to tab based app" onPress={this.onClickSwitchToTabs} />
18
         <Button title="Switch to app with side menus" onPress={this.onClickSwitchToSideMenus} />
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
         <Button title="Push" onPress={this.onClickPush} />
21
         <Button title="Push" onPress={this.onClickPush} />
21
         <Button title="Show Modal" onPress={this.onClickShowModal} />
22
         <Button title="Show Modal" onPress={this.onClickShowModal} />
22
         <Button title="Show Redbox" onPress={this.onClickShowRedbox} />
23
         <Button title="Show Redbox" onPress={this.onClickShowRedbox} />
105
   }
106
   }
106
 
107
 
107
   onClickLifecycleScreen() {
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