Daniel Zlotin пре 8 година
родитељ
комит
339bf42225

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java Прегледај датотеку

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

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java Прегледај датотеку

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

+ 3
- 2
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java Прегледај датотеку

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

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java Прегледај датотеку

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

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Прегледај датотеку

@@ -45,7 +45,7 @@ public class ViewPagerScreen extends Screen {
45 45
     private void addPages() {
46 46
         contentViews = new ArrayList<>();
47 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 49
             addContent(contentView);
50 50
             contentViews.add(contentView);
51 51
         }

+ 3
- 4
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Прегледај датотеку

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

+ 64
- 63
example-redux/src/app.js Прегледај датотеку

@@ -35,75 +35,76 @@ 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 39
         //  screen: {
71
-        //    screen: 'example.FirstTabScreen',
40
+        //    screen: 'example.LoginScreen',
72 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 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 108
         return;
108 109
       case 'after-login':
109 110
         Navigation.startTabBasedApp({

+ 2
- 2
example-redux/src/screens/FirstTabScreen.js Прегледај датотеку

@@ -69,7 +69,7 @@ class FirstTabScreen extends Component {
69 69
     console.log('selectedTabChanged ' + position);
70 70
     let rightButtons;
71 71
 
72
-    switch(position) {
72
+    switch (position) {
73 73
       case 0:
74 74
         rightButtons = [
75 75
           {
@@ -133,7 +133,7 @@ class FirstTabScreen extends Component {
133 133
         </TouchableOpacity>
134 134
 
135 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 137
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
138 138
         {this.props.obj && this.props.obj.arr ? <Text style={{fontWeight: '500'}}>Array prop: {this.props.obj.arr[0].str}</Text> : false}
139 139
       </View>

+ 9
- 1
src/deprecated/platformSpecificDeprecated.android.js Прегледај датотеку

@@ -18,6 +18,14 @@ function startSingleScreenApp(params) {
18 18
   addNavigatorButtons(screen);
19 19
   addNavigationStyleParams(screen);
20 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 29
   //const drawer = setupDrawer(params.drawer);
22 30
 
23 31
   /*
@@ -127,7 +135,7 @@ function adaptNavigationParams(screen) {
127 135
     navigatorID: screen.navigatorID,
128 136
     navigatorEventID: screen.navigatorEventID
129 137
   };
130
-  return _.omit(screen, ['screenInstanceID', 'navigatorID', 'navigatorEventID']);
138
+  return screen;
131 139
 }
132 140
 
133 141
 function startTabBasedApp(params) {

+ 0
- 1
src/platformSpecific.android.js Прегледај датотеку

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