Quellcode durchsuchen

proof that modal components get unmounted

Daniel Zlotin vor 8 Jahren
Ursprung
Commit
9ca72b515b
1 geänderte Dateien mit 36 neuen und 0 gelöschten Zeilen
  1. 36
    0
      example-redux/src/screens/LoginScreen.js

+ 36
- 0
example-redux/src/screens/LoginScreen.js Datei anzeigen

@@ -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({