Browse Source

Push screen from drawer in example app

Guy Carmeli 7 years ago
parent
commit
2e1a8526cd
2 changed files with 35 additions and 3 deletions
  1. 16
    0
      example/src/screens/Types.js
  2. 19
    3
      example/src/screens/types/Drawer.js

+ 16
- 0
example/src/screens/Types.js View File

4
 
4
 
5
 class Types extends Component {
5
 class Types extends Component {
6
 
6
 
7
+  constructor(props) {
8
+    super(props);
9
+    this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
10
+  }
11
+
12
+  onNavigatorEvent(event) {
13
+    if (event.type === 'DeepLink') {
14
+      const parts = event.link.split('/');
15
+      if (parts[0] === 'tab1') {
16
+        this.props.navigator.push({
17
+          screen: parts[1]
18
+        });
19
+      }
20
+    }
21
+  }
22
+
7
   toggleDrawer = () => {
23
   toggleDrawer = () => {
8
     this.props.navigator.toggleDrawer({
24
     this.props.navigator.toggleDrawer({
9
       side: 'left',
25
       side: 'left',

+ 19
- 3
example/src/screens/types/Drawer.js View File

4
 class MyClass extends React.Component {
4
 class MyClass extends React.Component {
5
 
5
 
6
   onShowModal = () => {
6
   onShowModal = () => {
7
-    this.props.navigator.toggleDrawer({
8
-      side: 'left'
9
-    });
7
+    this.toggleDrawer();
10
     this.props.navigator.showModal({
8
     this.props.navigator.showModal({
11
       screen: 'example.Types.Modal',
9
       screen: 'example.Types.Modal',
12
       title: `Modal`
10
       title: `Modal`
13
     });
11
     });
14
   };
12
   };
15
 
13
 
14
+  onPushToFirstTab = () => {
15
+    this.toggleDrawer();
16
+    this.props.navigator.handleDeepLink({
17
+      link: 'tab1/example.Types.Push'
18
+    });
19
+  };
20
+
21
+  toggleDrawer = () => {
22
+    this.props.navigator.toggleDrawer({
23
+      side: 'left'
24
+    });
25
+  };
26
+
16
   render() {
27
   render() {
17
     return (
28
     return (
18
       <View style={styles.container}>
29
       <View style={styles.container}>
21
             onPress={this.onShowModal}
32
             onPress={this.onShowModal}
22
             title="Show Modal"/>
33
             title="Show Modal"/>
23
         </View>
34
         </View>
35
+        <View style={styles.button}>
36
+          <Button
37
+            onPress={this.onPushToFirstTab}
38
+            title="Push to First Tab"/>
39
+        </View>
24
       </View>
40
       </View>
25
     );
41
     );
26
   }
42
   }