Просмотр исходного кода

Implement passProps in TopTabs screens

Guy Carmeli 8 лет назад
Родитель
Сommit
fa153d4bb0

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java Просмотреть файл

@@ -38,7 +38,10 @@ public class FragmentScreen extends Screen {
38 38
     }
39 39
 
40 40
     private void addContent() {
41
-        ContentView contentView = new ContentView(getContext(), screenParams, screenParams.screenId);
41
+        ContentView contentView = new ContentView(getContext(),
42
+                screenParams,
43
+                screenParams.screenId,
44
+                screenParams.passProps);
42 45
         addView(contentView, 0, 0);
43 46
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
44 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, screenParams.screenId, screenParams.passProps);
23 23
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
24 24
         if (screenParams.styleParams.drawScreenBelowTopBar) {
25 25
             params.addRule(BELOW, topBar.getId());

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Просмотреть файл

@@ -44,8 +44,8 @@ public class ViewPagerScreen extends Screen {
44 44
 
45 45
     private void addPages() {
46 46
         contentViews = new ArrayList<>();
47
-        for (TopTabParams topTabParam : screenParams.topTabParams) {
48
-            ContentView contentView = new ContentView(getContext(), screenParams, topTabParam.screenId);
47
+        for (TopTabParams tab : screenParams.topTabParams) {
48
+            ContentView contentView = new ContentView(getContext(), screenParams, tab.screenId, tab.passProps);
49 49
             addContent(contentView);
50 50
             contentViews.add(contentView);
51 51
         }

+ 5
- 7
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Просмотреть файл

@@ -14,15 +14,12 @@ public class ContentView extends ReactRootView {
14 14
     private final String screenId;
15 15
     private final String navigatorEventId;
16 16
     private final Bundle passProps;
17
-    private Bundle navigationParams;
18 17
 
19
-    public ContentView(Context context, ScreenParams screenParams, String screenId) {
18
+    public ContentView(Context context, ScreenParams screenParams, String screenId, Bundle passProps) {
20 19
         super(context);
21 20
         this.screenId = screenId;
22 21
         navigatorEventId = screenParams.navigatorEventId;
23
-
24
-        passProps = screenParams.passProps;
25
-        navigationParams = screenParams.navigationParams;
22
+        this.passProps = mergePropsAndNavigationParams(screenParams, passProps);
26 23
         attachToJS();
27 24
     }
28 25
 
@@ -44,10 +41,11 @@ public class ContentView extends ReactRootView {
44 41
 
45 42
     private void attachToJS() {
46 43
         ReactInstanceManager react = NavigationApplication.instance.getNavigationReactInstance().getReactInstanceManager();
47
-        startReactApplication(react, screenId, mergePropsAndNavigationParams());
44
+        startReactApplication(react, screenId, passProps);
48 45
     }
49 46
 
50
-    private Bundle mergePropsAndNavigationParams() {
47
+    private Bundle mergePropsAndNavigationParams(ScreenParams screenParams, Bundle passProps) {
48
+        Bundle navigationParams = (Bundle) screenParams.navigationParams.clone();
51 49
         if (passProps != null) {
52 50
             navigationParams.putAll(passProps);
53 51
         }