Sfoglia il codice sorgente

topTab passProps works

Daniel Zlotin 8 anni fa
parent
commit
339bf42225

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java Vedi File

1
 package com.reactnativenavigation.params;
1
 package com.reactnativenavigation.params;
2
 
2
 
3
+import android.os.Bundle;
4
+
3
 public class TopTabParams {
5
 public class TopTabParams {
4
     public String screenId;
6
     public String screenId;
5
     public String title;
7
     public String title;
8
+    public Bundle navigationParams;
6
 }
9
 }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java Vedi File

11
 public class TopTabParamsParser extends Parser {
11
 public class TopTabParamsParser extends Parser {
12
     private static final String KEY_SCREEN_ID = "screenId";
12
     private static final String KEY_SCREEN_ID = "screenId";
13
     private static final String KEY_TITLE = "title";
13
     private static final String KEY_TITLE = "title";
14
+    private static final String NAVIGATION_PARAMS = "navigationParams";
14
 
15
 
15
     @SuppressWarnings("ConstantConditions")
16
     @SuppressWarnings("ConstantConditions")
16
     public static List<TopTabParams> parse(Bundle params) {
17
     public static List<TopTabParams> parse(Bundle params) {
26
         TopTabParams result = new TopTabParams();
27
         TopTabParams result = new TopTabParams();
27
         result.screenId = params.getString(KEY_SCREEN_ID);
28
         result.screenId = params.getString(KEY_SCREEN_ID);
28
         result.title = params.getString(KEY_TITLE);
29
         result.title = params.getString(KEY_TITLE);
30
+        result.navigationParams = params.getBundle(NAVIGATION_PARAMS);
29
         return result;
31
         return result;
30
     }
32
     }
31
 }
33
 }

+ 3
- 2
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java Vedi File

39
 
39
 
40
     private void addContent() {
40
     private void addContent() {
41
         ContentView contentView = new ContentView(getContext(),
41
         ContentView contentView = new ContentView(getContext(),
42
-                screenParams,
43
-                screenParams.screenId);
42
+                screenParams.screenId,
43
+                screenParams.navigatorEventId,
44
+                screenParams.navigationParams);
44
         addView(contentView, 0, 0);
45
         addView(contentView, 0, 0);
45
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
46
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
46
         if (screenParams.styleParams.drawScreenBelowTopBar) {
47
         if (screenParams.styleParams.drawScreenBelowTopBar) {

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java Vedi File

19
 
19
 
20
     @Override
20
     @Override
21
     protected void createContent() {
21
     protected void createContent() {
22
-        contentView = new ContentView(getContext(), screenParams, screenParams.screenId);
22
+        contentView = new ContentView(getContext(), screenParams.screenId, screenParams.navigatorEventId, screenParams.navigationParams);
23
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
23
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
24
         if (screenParams.styleParams.drawScreenBelowTopBar) {
24
         if (screenParams.styleParams.drawScreenBelowTopBar) {
25
             params.addRule(BELOW, topBar.getId());
25
             params.addRule(BELOW, topBar.getId());

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Vedi File

45
     private void addPages() {
45
     private void addPages() {
46
         contentViews = new ArrayList<>();
46
         contentViews = new ArrayList<>();
47
         for (TopTabParams tab : screenParams.topTabParams) {
47
         for (TopTabParams tab : screenParams.topTabParams) {
48
-            ContentView contentView = new ContentView(getContext(), screenParams, tab.screenId);
48
+            ContentView contentView = new ContentView(getContext(), tab.screenId, screenParams.navigatorEventId, tab.navigationParams);
49
             addContent(contentView);
49
             addContent(contentView);
50
             contentViews.add(contentView);
50
             contentViews.add(contentView);
51
         }
51
         }

+ 3
- 4
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Vedi File

5
 
5
 
6
 import com.facebook.react.ReactRootView;
6
 import com.facebook.react.ReactRootView;
7
 import com.reactnativenavigation.NavigationApplication;
7
 import com.reactnativenavigation.NavigationApplication;
8
-import com.reactnativenavigation.params.ScreenParams;
9
 import com.reactnativenavigation.react.ReactViewHacks;
8
 import com.reactnativenavigation.react.ReactViewHacks;
10
 
9
 
11
 public class ContentView extends ReactRootView {
10
 public class ContentView extends ReactRootView {
14
     private final String navigatorEventId;
13
     private final String navigatorEventId;
15
     private final Bundle navigationParams;
14
     private final Bundle navigationParams;
16
 
15
 
17
-    public ContentView(Context context, ScreenParams screenParams, String screenId) {
16
+    public ContentView(Context context, String screenId, String navigatorEventId, Bundle navigationParams) {
18
         super(context);
17
         super(context);
19
         this.screenId = screenId;
18
         this.screenId = screenId;
20
-        navigatorEventId = screenParams.navigatorEventId;
21
-        navigationParams = screenParams.navigationParams;
19
+        this.navigatorEventId = navigatorEventId;
20
+        this.navigationParams = navigationParams;
22
         attachToJS();
21
         attachToJS();
23
     }
22
     }
24
 
23
 

+ 64
- 63
example-redux/src/app.js Vedi File

35
   startApp(root) {
35
   startApp(root) {
36
     switch (root) {
36
     switch (root) {
37
       case 'login':
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
         //Navigation.startSingleScreenApp({
38
         //Navigation.startSingleScreenApp({
70
         //  screen: {
39
         //  screen: {
71
-        //    screen: 'example.FirstTabScreen',
40
+        //    screen: 'example.LoginScreen',
72
         //    title: 'Login',
41
         //    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
-        //        }
102
-        //      }
103
-        //    ],
104
         //    navigatorStyle: {}
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
+        //    }
105
         //  }
67
         //  }
106
         //});
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
+        });
107
         return;
108
         return;
108
       case 'after-login':
109
       case 'after-login':
109
         Navigation.startTabBasedApp({
110
         Navigation.startTabBasedApp({

+ 2
- 2
example-redux/src/screens/FirstTabScreen.js Vedi File

69
     console.log('selectedTabChanged ' + position);
69
     console.log('selectedTabChanged ' + position);
70
     let rightButtons;
70
     let rightButtons;
71
 
71
 
72
-    switch(position) {
72
+    switch (position) {
73
       case 0:
73
       case 0:
74
         rightButtons = [
74
         rightButtons = [
75
           {
75
           {
133
         </TouchableOpacity>
133
         </TouchableOpacity>
134
 
134
 
135
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
135
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
136
-        <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
136
+        <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn ? this.props.fn() : ''}</Text>
137
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
137
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
138
         {this.props.obj && this.props.obj.arr ? <Text style={{fontWeight: '500'}}>Array prop: {this.props.obj.arr[0].str}</Text> : false}
138
         {this.props.obj && this.props.obj.arr ? <Text style={{fontWeight: '500'}}>Array prop: {this.props.obj.arr[0].str}</Text> : false}
139
       </View>
139
       </View>

+ 9
- 1
src/deprecated/platformSpecificDeprecated.android.js Vedi File

18
   addNavigatorButtons(screen);
18
   addNavigatorButtons(screen);
19
   addNavigationStyleParams(screen);
19
   addNavigationStyleParams(screen);
20
   screen.passProps = params.passProps;
20
   screen.passProps = params.passProps;
21
+
22
+  if (screen.topTabs) {
23
+    _.forEach(screen.topTabs, (tab) => {
24
+      addNavigatorParams(tab);
25
+      adaptNavigationParams(tab);
26
+    });
27
+  }
28
+
21
   //const drawer = setupDrawer(params.drawer);
29
   //const drawer = setupDrawer(params.drawer);
22
 
30
 
23
   /*
31
   /*
127
     navigatorID: screen.navigatorID,
135
     navigatorID: screen.navigatorID,
128
     navigatorEventID: screen.navigatorEventID
136
     navigatorEventID: screen.navigatorEventID
129
   };
137
   };
130
-  return _.omit(screen, ['screenInstanceID', 'navigatorID', 'navigatorEventID']);
138
+  return screen;
131
 }
139
 }
132
 
140
 
133
 function startTabBasedApp(params) {
141
 function startTabBasedApp(params) {

+ 0
- 1
src/platformSpecific.android.js Vedi File

60
 function savePassProps(params) {
60
 function savePassProps(params) {
61
   //TODO this needs to be handled in a common place,
61
   //TODO this needs to be handled in a common place,
62
   //TODO also, all global passProps should be handled differently
62
   //TODO also, all global passProps should be handled differently
63
-  //TODO also, topTabs passProps not working
64
   if (params.navigationParams && params.passProps) {
63
   if (params.navigationParams && params.passProps) {
65
     PropRegistry.save(params.navigationParams.screenInstanceID, params.passProps);
64
     PropRegistry.save(params.navigationParams.screenInstanceID, params.passProps);
66
   }
65
   }