Browse Source

Add SideMenu to BottomTabsActivity

Guy Carmeli 8 years ago
parent
commit
3f043cc1ec

+ 83
- 77
example-redux/src/app.js View File

@@ -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({
@@ -121,7 +121,7 @@ export default class App {
121 121
               icon: require('../img/one.png'),
122 122
               selectedIcon: require('../img/one_selected.png'),
123 123
               title: 'Screen One',
124
-              navigatorStyle: {},
124
+              navigatorStyle: {}
125 125
             },
126 126
             {
127 127
               label: 'Two',
@@ -129,7 +129,7 @@ export default class App {
129 129
               icon: require('../img/two.png'),
130 130
               selectedIcon: require('../img/two_selected.png'),
131 131
               title: 'Screen Two',
132
-              navigatorStyle: {},
132
+              navigatorStyle: {}
133 133
             }
134 134
           ],
135 135
           passProps: {
@@ -145,7 +145,13 @@ export default class App {
145 145
             num: 1234
146 146
           },
147 147
           animationType: 'slide-down',
148
-          title: 'Redux Example'
148
+          title: 'Redux Example',
149
+          drawer: { // optional, add this if you want a side menu drawer in your app
150
+            left: { // optional, define if you want a drawer from the left
151
+              screen: 'example.BottomTabsSideMenu' // unique ID registered with Navigation.registerScreen
152
+            },
153
+            disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
154
+          }
149 155
         });
150 156
         return;
151 157
       default:

+ 79
- 0
example-redux/src/screens/BottomTabsSideMenu.js View File

@@ -0,0 +1,79 @@
1
+import React, {Component, PropTypes} from 'react';
2
+import {
3
+  Text,
4
+  View,
5
+  ScrollView,
6
+  TouchableOpacity,
7
+  StyleSheet,
8
+  Alert
9
+} from 'react-native';
10
+import {connect} from 'react-redux';
11
+import * as counterActions from '../reducers/counter/actions';
12
+import _ from 'lodash';
13
+
14
+class SideMenu extends Component {
15
+
16
+  constructor(props) {
17
+    super(props);
18
+    // if you want to listen on navigator events, set this up
19
+    this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
20
+  }
21
+
22
+  onNavigatorEvent(event) {
23
+      console.log('SideMenu', 'Unhandled event ' + event.id);
24
+  }
25
+
26
+  render() {
27
+    return (
28
+      <View style={styles.sideMenu}>
29
+        <Text style={styles.title}>Hello from SideMenu</Text>
30
+
31
+        <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
32
+          <Text style={styles.button}>Show modal</Text>
33
+        </TouchableOpacity>
34
+      </View>
35
+    );
36
+  }
37
+
38
+  onShowModalPress() {
39
+    this.props.navigator.showModal({
40
+      title: "Modal Screen from SideMenu",
41
+      screen: "example.PushedScreen",
42
+      passProps: {
43
+        str: 'This is a prop passed in \'navigator.showModal()\'!',
44
+        obj: {
45
+          str: 'This is a prop passed in an object!',
46
+          arr: [
47
+            {
48
+              str: 'This is a prop in an object in an array in an object!'
49
+            }
50
+          ]
51
+        },
52
+        num: 1234
53
+      }
54
+    });
55
+  }
56
+}
57
+
58
+const styles = StyleSheet.create({
59
+  sideMenu: {
60
+    flex: 1,
61
+    backgroundColor: '#efefef',
62
+    padding: 20
63
+  },
64
+  title: {
65
+    textAlign: 'center',
66
+    marginBottom: 15
67
+  },
68
+  button: {
69
+    textAlign: 'center',
70
+    fontSize: 18,
71
+    borderBottomWidth: 1,
72
+    borderColor: 'grey',
73
+    marginBottom: 10,
74
+    marginTop:10,
75
+    color: 'black'
76
+  }
77
+});
78
+
79
+export default connect()(SideMenu);

+ 2
- 2
example-redux/src/screens/SideMenu.js View File

@@ -32,7 +32,7 @@ class SideMenu extends Component {
32 32
           <Text style={styles.button}>Show modal</Text>
33 33
         </TouchableOpacity>
34 34
 
35
-        <TouchableOpacity onPress={ this.onPushScreenToTabOne.bind(this) }>
35
+        <TouchableOpacity onPress={ this.onPushScreen.bind(this) }>
36 36
           <Text style={styles.button}>Push screen</Text>
37 37
         </TouchableOpacity>
38 38
       </View>
@@ -58,7 +58,7 @@ class SideMenu extends Component {
58 58
     });
59 59
   }
60 60
 
61
-  onPushScreenToTabOne() {
61
+  onPushScreen() {
62 62
     this.props.navigator.handleDeepLink({
63 63
       link: 'tab1/pushScreen/example.PushedScreen'
64 64
     });

+ 2
- 0
example-redux/src/screens/index.js View File

@@ -6,6 +6,7 @@ import SecondTabScreen from './SecondTabScreen';
6 6
 import PushedScreen from './PushedScreen';
7 7
 import ListScreen from './ListScreen';
8 8
 import SideMenu from './SideMenu';
9
+import BottomTabsSideMenu from './BottomTabsSideMenu';
9 10
 
10 11
 // register all screens of the app (including internal ones)
11 12
 export function registerScreens(store, Provider) {
@@ -15,4 +16,5 @@ export function registerScreens(store, Provider) {
15 16
   Navigation.registerComponent('example.PushedScreen', () => PushedScreen, store, Provider);
16 17
   Navigation.registerComponent('example.ListScreen', () => ListScreen, store, Provider);
17 18
   Navigation.registerComponent('example.SideMenu', () => SideMenu, store, Provider);
19
+  Navigation.registerComponent('example.BottomTabsSideMenu', () => BottomTabsSideMenu, store, Provider);
18 20
 }