Selaa lähdekoodia

Pushed screen from SideMenu

Guy Carmeli 8 vuotta sitten
vanhempi
commit
eb65b1af0f
2 muutettua tiedostoa jossa 82 lisäystä ja 6 poistoa
  1. 25
    3
      example-redux/src/screens/ListScreen.js
  2. 57
    3
      example-redux/src/screens/SideMenu.js

+ 25
- 3
example-redux/src/screens/ListScreen.js Näytä tiedosto

@@ -30,15 +30,37 @@ class ListScreen extends Component {
30 30
 
31 31
   constructor(props) {
32 32
     super(props);
33
-
33
+    this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
34
+    
34 35
     var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
35 36
     this.state = {
36 37
       dataSource: ds.cloneWithRows(this._genRows({}))
37 38
     }
38 39
   }
39 40
 
40
-  componentWillMount() {
41
-    this._pressData = {};
41
+  onNavigatorEvent(event) {
42
+    if (event.type == 'DeepLink') {
43
+      const parts = event.link.split('/');
44
+      if (parts[0] == 'tab1' && parts[1] == 'pushScreen') {
45
+        this.props.navigator.push({
46
+          title: "Pushed from SideMenu",
47
+          screen: parts[2],
48
+          passProps: {
49
+            str: 'This is a prop passed in \'navigator.push()\'!',
50
+            obj: {
51
+              str: 'This is a prop passed in an object!',
52
+              arr: [
53
+                {
54
+                  str: 'This is a prop in an object in an array in an object!'
55
+                }
56
+              ]
57
+            },
58
+            num: 1234
59
+          }
60
+        });
61
+      }
62
+    }
63
+      console.log('ListScreen', 'Unhandled event ' + event.id);
42 64
   }
43 65
 
44 66
   render() {

+ 57
- 3
example-redux/src/screens/SideMenu.js Näytä tiedosto

@@ -20,16 +20,70 @@ class SideMenu extends Component {
20 20
   }
21 21
 
22 22
   onNavigatorEvent(event) {
23
-      console.log('Unhandled event ' + event.id);
23
+      console.log('SideMenu', 'Unhandled event ' + event.id);
24 24
   }
25 25
 
26 26
   render() {
27 27
     return (
28
-      <View style={{flex: 1, padding: 20, backgroundColor: 'green'}}>
29
-        <Text>Hello from SideMenu</Text>
28
+      <View style={styles.sideMenu}>
29
+        <Text style={styles.title}>Hello from SideMenu</Text>
30
+
31
+        <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
32
+          <Text style={styles.button}>Show modal</Text>
33
+        </TouchableOpacity>
34
+
35
+        <TouchableOpacity onPress={ this.onPushScreenToTabOne.bind(this) }>
36
+          <Text style={styles.button}>Push screen to tab 1</Text>
37
+        </TouchableOpacity>
30 38
       </View>
31 39
     );
32 40
   }
41
+
42
+  onShowModalPress() {
43
+    this.props.navigator.showModal({
44
+      title: "Modal Screen from SideMenu",
45
+      screen: "example.PushedScreen",
46
+      passProps: {
47
+        str: 'This is a prop passed in \'navigator.showModal()\'!',
48
+        obj: {
49
+          str: 'This is a prop passed in an object!',
50
+          arr: [
51
+            {
52
+              str: 'This is a prop in an object in an array in an object!'
53
+            }
54
+          ]
55
+        },
56
+        num: 1234
57
+      }
58
+    });
59
+  }
60
+
61
+  onPushScreenToTabOne() {
62
+    this.props.navigator.handleDeepLink({
63
+      link: 'tab1/pushScreen/example.PushedScreen'
64
+    });
65
+  }
33 66
 }
34 67
 
68
+const styles = StyleSheet.create({
69
+  sideMenu: {
70
+    flex: 1,
71
+    backgroundColor: '#efefef',
72
+    padding: 20
73
+  },
74
+  title: {
75
+    textAlign: 'center',
76
+    marginBottom: 15
77
+  },
78
+  button: {
79
+    textAlign: 'center',
80
+    fontSize: 18,
81
+    borderBottomWidth: 1,
82
+    borderColor: 'grey',
83
+    marginBottom: 10,
84
+    marginTop:10,
85
+    color: 'black'
86
+  }
87
+});
88
+
35 89
 export default connect()(SideMenu);