Browse Source

Add switch to tab example with out specified index

Guy Carmeli 8 years ago
parent
commit
6f08f751dc

+ 10
- 0
example-redux/src/screens/FirstTabScreen.js View File

@@ -147,6 +147,10 @@ class FirstTabScreen extends Component {
147 147
           <Text style={styles.button}>Toggle Drawer</Text>
148 148
         </TouchableOpacity>
149 149
 
150
+        <TouchableOpacity onPress={ this.onSelectSecondTabPress.bind(this) }>
151
+          <Text style={styles.button}>Select Second Tab</Text>
152
+        </TouchableOpacity>
153
+
150 154
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
151 155
         <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn ? this.props.fn() : ''}</Text>
152 156
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
@@ -248,6 +252,12 @@ class FirstTabScreen extends Component {
248 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 263
 const styles = StyleSheet.create({

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

@@ -108,34 +108,41 @@ class SecondTabScreen extends Component {
108 108
 
109 109
   handleDeepLink(event) {
110 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 148
 const styles = StyleSheet.create({