瀏覽代碼

proof that modal components get unmounted

Daniel Zlotin 8 年之前
父節點
當前提交
9ca72b515b
共有 1 個檔案被更改,包括 36 行新增0 行删除
  1. 36
    0
      example-redux/src/screens/LoginScreen.js

+ 36
- 0
example-redux/src/screens/LoginScreen.js 查看文件

@@ -23,6 +23,10 @@ class LoginScreen extends Component {
23 23
     super(props);
24 24
   }
25 25
 
26
+  componentWillUnmount() {
27
+    console.log('Component-Lifecycle', 'componentWillUnmount', 'LoginScreen');
28
+  }
29
+
26 30
   render() {
27 31
     return (
28 32
       <View style={{flex: 1, padding: 20}}>
@@ -39,6 +43,10 @@ class LoginScreen extends Component {
39 43
           <Text style={styles.button}>Login</Text>
40 44
         </TouchableOpacity>
41 45
 
46
+        <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
47
+          <Text style={styles.button}>Show another login as modal</Text>
48
+        </TouchableOpacity>
49
+
42 50
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
43 51
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
44 52
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
@@ -56,6 +64,34 @@ class LoginScreen extends Component {
56 64
   onLoginPress() {
57 65
     this.props.dispatch(appActions.login());
58 66
   }
67
+
68
+  onShowModalPress() {
69
+    this.props.navigator.showModal({
70
+      screen: 'example.LoginScreen',
71
+      title: 'Login',
72
+      passProps: {
73
+        str: 'This is a prop passed in \'startSingleScreenApp()\'!',
74
+        obj: {
75
+          str: 'This is a prop passed in an object!',
76
+          arr: [
77
+            {
78
+              str: 'This is a prop in an object in an array in an object!'
79
+            }
80
+          ],
81
+          arr2: [
82
+            [
83
+              'array of strings',
84
+              'with two strings'
85
+            ],
86
+            [
87
+              1, 2, 3
88
+            ]
89
+          ]
90
+        },
91
+        num: 1234
92
+      }
93
+    });
94
+  }
59 95
 }
60 96
 
61 97
 const styles = StyleSheet.create({