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,6 +4,22 @@ import Row from '../components/Row';
4 4
 
5 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 23
   toggleDrawer = () => {
8 24
     this.props.navigator.toggleDrawer({
9 25
       side: 'left',

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

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