Przeglądaj źródła

Add tabSelected logic to example-redux

Guy Carmeli 8 lat temu
rodzic
commit
e9ea6274e0

+ 74
- 74
example-redux/src/app.js Wyświetl plik

@@ -35,82 +35,82 @@ export default class App {
35 35
   startApp(root) {
36 36
     switch (root) {
37 37
       case 'login':
38
-        Navigation.startSingleScreenApp({
39
-         screen: {
40
-           screen: 'example.LoginScreen',
41
-           title: 'Login',
42
-           navigatorStyle: {}
43
-         },
44
-         passProps: {
45
-           str: 'This is a prop passed in \'startSingleScreenApp()\'!',
46
-           obj: {
47
-             str: 'This is a prop passed in an object!',
48
-             arr: [
49
-               {
50
-                 str: 'This is a prop in an object in an array in an object!'
51
-               }
52
-             ],
53
-             arr2: [
54
-               [
55
-                 'array of strings',
56
-                 'with two strings'
57
-               ],
58
-               [
59
-                 1, 2, 3
60
-               ]
61
-             ]
62
-           },
63
-           num: 1234,
64
-           fn: function() {
65
-             return 'Hello from a function!';
66
-           }
67
-         }
68
-        });
69 38
         // Navigation.startSingleScreenApp({
70
-        //   screen: {
71
-        //     screen: 'example.FirstTabScreen',
72
-        //     title: 'Login',
73
-        //     topTabs: [
74
-        //       {
75
-        //         screenId: 'example.ListScreen',
76
-        //         title: 'Tab1',
77
-        //         passProps: {
78
-        //           str: 'This is a prop passed to Tab1'
79
-        //         }
80
-        //       },
81
-        //       {
82
-        //         screenId: 'example.PushedScreen',
83
-        //         title: 'Tab2',
84
-        //         passProps: {
85
-        //           str: 'This is a prop passed to Tab2'
86
-        //         }
87
-        //
88
-        //       },
89
-        //       {
90
-        //         screenId: 'example.PushedScreen',
91
-        //         title: 'Tab3',
92
-        //         passProps: {
93
-        //           str: 'This is a prop passed to Tab3'
94
-        //         }
95
-        //       },
96
-        //       {
97
-        //         screenId: 'example.FirstTabScreen',
98
-        //         title: 'Tab4',
99
-        //         passProps: {
100
-        //           str: 'This is a prop passed to Tab4',
101
-        //           fn: () => 'Hello from a function passed as passProps!'
102
-        //         }
103
-        //       }
104
-        //     ],
105
-        //     navigatorStyle: {}
106
-        //   },
107
-        //   drawer: { // optional, add this if you want a side menu drawer in your app
108
-        //     left: { // optional, define if you want a drawer from the left
109
-        //       screen: 'example.SideMenu' // unique ID registered with Navigation.registerScreen
110
-        //     },
111
-        //     disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
112
-        //   }
39
+        //  screen: {
40
+        //    screen: 'example.LoginScreen',
41
+        //    title: 'Login',
42
+        //    navigatorStyle: {}
43
+        //  },
44
+        //  passProps: {
45
+        //    str: 'This is a prop passed in \'startSingleScreenApp()\'!',
46
+        //    obj: {
47
+        //      str: 'This is a prop passed in an object!',
48
+        //      arr: [
49
+        //        {
50
+        //          str: 'This is a prop in an object in an array in an object!'
51
+        //        }
52
+        //      ],
53
+        //      arr2: [
54
+        //        [
55
+        //          'array of strings',
56
+        //          'with two strings'
57
+        //        ],
58
+        //        [
59
+        //          1, 2, 3
60
+        //        ]
61
+        //      ]
62
+        //    },
63
+        //    num: 1234,
64
+        //    fn: function() {
65
+        //      return 'Hello from a function!';
66
+        //    }
67
+        //  }
113 68
         // });
69
+        Navigation.startSingleScreenApp({
70
+          screen: {
71
+            screen: 'example.FirstTabScreen',
72
+            title: 'Login',
73
+            topTabs: [
74
+              {
75
+                screenId: 'example.ListScreen',
76
+                title: 'Tab1',
77
+                passProps: {
78
+                  str: 'This is a prop passed to Tab1'
79
+                }
80
+              },
81
+              {
82
+                screenId: 'example.PushedScreen',
83
+                title: 'Tab2',
84
+                passProps: {
85
+                  str: 'This is a prop passed to Tab2'
86
+                }
87
+
88
+              },
89
+              {
90
+                screenId: 'example.PushedScreen',
91
+                title: 'Tab3',
92
+                passProps: {
93
+                  str: 'This is a prop passed to Tab3'
94
+                }
95
+              },
96
+              {
97
+                screenId: 'example.FirstTabScreen',
98
+                title: 'Tab4',
99
+                passProps: {
100
+                  str: 'This is a prop passed to Tab4',
101
+                  fn: () => 'Hello from a function passed as passProps!'
102
+                }
103
+              }
104
+            ],
105
+            navigatorStyle: {}
106
+          },
107
+          drawer: { // optional, add this if you want a side menu drawer in your app
108
+            left: { // optional, define if you want a drawer from the left
109
+              screen: 'example.SideMenu' // unique ID registered with Navigation.registerScreen
110
+            },
111
+            disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
112
+          }
113
+        });
114 114
         return;
115 115
       case 'after-login':
116 116
         Navigation.startTabBasedApp({

+ 49
- 26
example-redux/src/screens/ListScreen.js Wyświetl plik

@@ -40,33 +40,56 @@ class ListScreen extends Component {
40 40
 
41 41
   onNavigatorEvent(event) {
42 42
     if (event.type == 'DeepLink') {
43
-      const parts = event.link.split('/');
44
-      if (parts[0] == 'tab1' && parts[1] == 'pushScreen') {
45
-        this.props.navigator.toggleDrawer({
46
-          side: 'left',
47
-          animated: true,
48
-          to: 'closed'
49
-        });
50
-
51
-        this.props.navigator.push({
52
-          title: "Pushed from SideMenu",
53
-          screen: parts[2],
54
-          passProps: {
55
-            str: 'This is a prop passed in \'navigator.push()\'!',
56
-            obj: {
57
-              str: 'This is a prop passed in an object!',
58
-              arr: [
59
-                {
60
-                  str: 'This is a prop in an object in an array in an object!'
61
-                }
62
-              ]
63
-            },
64
-            num: 1234
65
-          }
66
-        });
67
-      }
43
+      this.handleDeepLink(event);
44
+      return;
68 45
     }
69
-      console.log('ListScreen', 'Unhandled event ' + event.id);
46
+
47
+    if (event.id == 'tabSelected') {
48
+      this.onTabSelected();
49
+      return;
50
+    }
51
+
52
+    console.log('ListScreen', 'Unhandled event ' + event.id);
53
+  }
54
+
55
+  handleDeepLink(event) {
56
+    const parts = event.link.split('/');
57
+    if (parts[0] == 'tab1' && parts[1] == 'pushScreen') {
58
+      this.props.navigator.toggleDrawer({
59
+        side: 'left',
60
+        animated: true,
61
+        to: 'closed'
62
+      });
63
+
64
+      this.props.navigator.push({
65
+        title: "Pushed from SideMenu",
66
+        screen: parts[2],
67
+        passProps: {
68
+          str: 'This is a prop passed in \'navigator.push()\'!',
69
+          obj: {
70
+            str: 'This is a prop passed in an object!',
71
+            arr: [
72
+              {
73
+                str: 'This is a prop in an object in an array in an object!'
74
+              }
75
+            ]
76
+          },
77
+          num: 1234
78
+        }
79
+      });
80
+    }
81
+  }
82
+
83
+  onTabSelected() {
84
+    console.log('ListScreen', 'onTabSelected');
85
+    this.props.navigator.setButtons({
86
+      rightButtons: [
87
+        {
88
+          id: 'account',
89
+          icon: require('../../img/ic_account_box_.png')
90
+        }
91
+      ]
92
+    });
70 93
   }
71 94
 
72 95
   render() {

+ 17
- 0
example-redux/src/screens/PushedScreen.js Wyświetl plik

@@ -67,11 +67,28 @@ class PushedScreen extends Component {
67 67
         this.handleBackPress();
68 68
         break;
69 69
 
70
+      case 'tabSelected':
71
+        this.onTabSelected();
72
+        break;
73
+
70 74
       default:
71 75
         console.log('PushedScreen', 'Unknown event ' + event.id);
72 76
     }
73 77
   }
74 78
 
79
+  onTabSelected() {
80
+    console.log('PushedScreen', 'onTabSelected');
81
+    this.props.navigator.setButtons({
82
+      rightButtons: [
83
+        {
84
+          id: 'account',
85
+          icon: require('../../img/ic_add_alert.png')
86
+        }
87
+      ]
88
+    });
89
+  }
90
+
91
+
75 92
   handleBackPress() {
76 93
     Alert.alert(
77 94
       'Back button press!',