Просмотр исходного кода

Add switch to tab example with out specified index

Guy Carmeli 8 лет назад
Родитель
Сommit
6f08f751dc
2 измененных файлов: 42 добавлений и 25 удалений
  1. 10
    0
      example-redux/src/screens/FirstTabScreen.js
  2. 32
    25
      example-redux/src/screens/SecondTabScreen.js

+ 10
- 0
example-redux/src/screens/FirstTabScreen.js Просмотреть файл

147
           <Text style={styles.button}>Toggle Drawer</Text>
147
           <Text style={styles.button}>Toggle Drawer</Text>
148
         </TouchableOpacity>
148
         </TouchableOpacity>
149
 
149
 
150
+        <TouchableOpacity onPress={ this.onSelectSecondTabPress.bind(this) }>
151
+          <Text style={styles.button}>Select Second Tab</Text>
152
+        </TouchableOpacity>
153
+
150
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
154
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
151
         <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn ? this.props.fn() : ''}</Text>
155
         <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn ? this.props.fn() : ''}</Text>
152
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
156
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
248
       animated: true
252
       animated: true
249
     })
253
     })
250
   }
254
   }
255
+
256
+  onSelectSecondTabPress() {
257
+    this.props.navigator.handleDeepLink({
258
+      link: 'tab2/select'
259
+    })
260
+  }
251
 }
261
 }
252
 
262
 
253
 const styles = StyleSheet.create({
263
 const styles = StyleSheet.create({

+ 32
- 25
example-redux/src/screens/SecondTabScreen.js Просмотреть файл

108
 
108
 
109
   handleDeepLink(event) {
109
   handleDeepLink(event) {
110
     const parts = event.link.split('/');
110
     const parts = event.link.split('/');
111
-    if (parts[0] == 'tab2' && parts[1] == 'pushScreen') {
112
-      this.props.navigator.toggleDrawer({
113
-        side: 'left',
114
-        animated: true,
115
-        to: 'closed'
116
-      });
117
-
118
-      this.props.navigator.push({
119
-        title: "Pushed from SideMenu",
120
-        screen: parts[2],
121
-        passProps: {
122
-          str: 'This is a prop passed in \'navigator.push()\'!',
123
-          obj: {
124
-            str: 'This is a prop passed in an object!',
125
-            arr: [
126
-              {
127
-                str: 'This is a prop in an object in an array in an object!'
128
-              }
129
-            ]
130
-          },
131
-          num: 1234
132
-        }
133
-      });
134
-    }
135
-    return;
111
+    if (parts[0] == 'tab2') {
112
+      if (parts[1] == 'select') {
113
+        this.props.navigator.switchToTab({});
114
+      }
136
 
115
 
116
+      if (parts[1] == 'pushScreen') {
117
+        this.pushScreenFromSideMenu();
118
+      }
119
+    }
137
   }
120
   }
138
 
121
 
122
+  pushScreenFromSideMenu() {
123
+    this.props.navigator.toggleDrawer({
124
+      side: 'left',
125
+      animated: true,
126
+      to: 'closed'
127
+    });
128
+
129
+    this.props.navigator.push({
130
+      title: "Pushed from SideMenu",
131
+      screen: parts[2],
132
+      passProps: {
133
+        str: 'This is a prop passed in \'navigator.push()\'!',
134
+        obj: {
135
+          str: 'This is a prop passed in an object!',
136
+          arr: [
137
+            {
138
+              str: 'This is a prop in an object in an array in an object!'
139
+            }
140
+          ]
141
+        },
142
+        num: 1234
143
+      }
144
+    });
145
+  }
139
 }
146
 }
140
 
147
 
141
 const styles = StyleSheet.create({
148
 const styles = StyleSheet.create({