Browse Source

Add push screens buttons to SideMenu

Guy Carmeli 8 years ago
parent
commit
a0a997104a

+ 21
- 0
example-redux/src/screens/BottomTabsSideMenu.js View File

31
         <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
31
         <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
32
           <Text style={styles.button}>Show modal</Text>
32
           <Text style={styles.button}>Show modal</Text>
33
         </TouchableOpacity>
33
         </TouchableOpacity>
34
+
35
+        <TouchableOpacity onPress={ this.onPushScreenToFirstTab.bind(this) }>
36
+          <Text style={styles.button}>Push screen to first tab</Text>
37
+        </TouchableOpacity>
38
+
39
+        <TouchableOpacity onPress={ this.onPushScreenToSecondTab.bind(this) }>
40
+          <Text style={styles.button}>Push screen to second tab</Text>
41
+        </TouchableOpacity>
34
       </View>
42
       </View>
35
     );
43
     );
36
   }
44
   }
53
       }
61
       }
54
     });
62
     });
55
   }
63
   }
64
+
65
+  onPushScreenToFirstTab() {
66
+    this.props.navigator.handleDeepLink({
67
+      link: 'tab1/pushScreen/example.PushedScreen'
68
+    });
69
+  }
70
+
71
+  onPushScreenToSecondTab() {
72
+    console.log('SideMenu', 'onPushScreenToSecondTab ' + 'tab2/pushScreen/example.PushedScreen');
73
+    this.props.navigator.handleDeepLink({
74
+      link: 'tab2/pushScreen/example.PushedScreen'
75
+    });
76
+  }
56
 }
77
 }
57
 
78
 
58
 const styles = StyleSheet.create({
79
 const styles = StyleSheet.create({

+ 2
- 1
example-redux/src/screens/LoginScreen.js View File

47
           <Text style={styles.button}>Show another login as modal</Text>
47
           <Text style={styles.button}>Show another login as modal</Text>
48
         </TouchableOpacity>
48
         </TouchableOpacity>
49
 
49
 
50
-        <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn()}</Text>
50
+        // TODO: Uncomment when fixed -guyca
51
+        {/*<Text style={{fontWeight: '500'}}>Function prop: {this.props.fn()}</Text> */}
51
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
52
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
52
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
53
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
53
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
54
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>

+ 32
- 0
example-redux/src/screens/SecondTabScreen.js View File

22
   constructor(props) {
22
   constructor(props) {
23
     super(props);
23
     super(props);
24
     this.buttonsCounter = 0;
24
     this.buttonsCounter = 0;
25
+    this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
25
   }
26
   }
26
 
27
 
27
   render() {
28
   render() {
80
   }
81
   }
81
 
82
 
82
   onNavigatorEvent(event) {
83
   onNavigatorEvent(event) {
84
+    if (event.type == 'DeepLink') {
85
+      console.log('SecondTabScreen', 'onNavigatorEvent ' + event.link);
86
+      const parts = event.link.split('/');
87
+      if (parts[0] == 'tab2' && parts[1] == 'pushScreen') {
88
+        this.props.navigator.toggleDrawer({
89
+          side: 'left',
90
+          animated: true,
91
+          to: 'closed'
92
+        });
93
+
94
+        this.props.navigator.push({
95
+          title: "Pushed from SideMenu",
96
+          screen: parts[2],
97
+          passProps: {
98
+            str: 'This is a prop passed in \'navigator.push()\'!',
99
+            obj: {
100
+              str: 'This is a prop passed in an object!',
101
+              arr: [
102
+                {
103
+                  str: 'This is a prop in an object in an array in an object!'
104
+                }
105
+              ]
106
+            },
107
+            num: 1234
108
+          }
109
+        });
110
+      }
111
+      return;
112
+    }
113
+
83
     switch (event.id) {
114
     switch (event.id) {
84
       case 'left':
115
       case 'left':
85
         Alert.alert('NavBar', 'Left button pressed');
116
         Alert.alert('NavBar', 'Left button pressed');
88
         Alert.alert('NavBar', 'Right button pressed');
119
         Alert.alert('NavBar', 'Right button pressed');
89
         break;
120
         break;
90
     }
121
     }
122
+    console.log('ListScreen', 'Unhandled event ' + event.id);
91
   }
123
   }
92
 }
124
 }
93
 
125