Daniel Zlotin 8 年前
父节点
当前提交
975acf2fb8

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/params/ScreenStyleParams.java 查看文件

@@ -41,5 +41,5 @@ public class ScreenStyleParams {
41 41
 
42 42
     public Color navigationBarColor;
43 43
 
44
-    public boolean drawUnderTopBar;
44
+    public boolean drawBelowTopBar;
45 45
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenStyleParamsParser.java 查看文件

@@ -26,7 +26,7 @@ public class ScreenStyleParamsParser {
26 26
                 new ScreenStyleParams.Color(ColorParser.parse(params.getString("bottomTabsButtonColor")));
27 27
         result.selectedBottomTabsButtonColor =
28 28
                 new ScreenStyleParams.Color(ColorParser.parse(params.getString("selectedBottomTabsButtonColor")));
29
-        result.drawUnderTopBar = params.getBoolean("drawUnderTopBar", false);
29
+        result.drawBelowTopBar = params.getBoolean("drawBelowTopBar", false);
30 30
         return result;
31 31
     }
32 32
 }

+ 6
- 9
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java 查看文件

@@ -4,7 +4,6 @@ import android.app.Fragment;
4 4
 import android.app.FragmentManager;
5 5
 import android.app.FragmentTransaction;
6 6
 import android.os.Bundle;
7
-import android.support.annotation.NonNull;
8 7
 import android.support.annotation.Nullable;
9 8
 import android.support.v7.app.AppCompatActivity;
10 9
 import android.widget.FrameLayout;
@@ -34,20 +33,18 @@ public class FragmentScreen extends Screen {
34 33
     protected void createContent() {
35 34
         content = new FrameLayout(getContext());
36 35
         content.setId(ViewUtils.generateViewId());
37
-        ContentView contentView = new ContentView(getContext(), screenParams.screenId, screenParams.passProps, screenParams.navigationParams, null);
38
-        addView(contentView, 0, 0);
39
-        addView(content, addBelowTopBar());
36
+        addContent();
40 37
         addFragment();
41
-        contentView.init();
42 38
     }
43 39
 
44
-    @NonNull
45
-    private LayoutParams addBelowTopBar() {
40
+    private void addContent() {
41
+        ContentView contentView = new ContentView(getContext(), screenParams.screenId, screenParams.passProps, screenParams.navigationParams, null);
42
+        addView(contentView, 0, 0);
46 43
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
47
-        if (!screenParams.styleParams.drawUnderTopBar) {
44
+        if (screenParams.styleParams.drawBelowTopBar) {
48 45
             params.addRule(BELOW, topBar.getId());
49 46
         }
50
-        return params;
47
+        addView(content, params);
51 48
     }
52 49
 
53 50
 

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ScreenFactory.java 查看文件

@@ -12,7 +12,7 @@ public class ScreenFactory {
12 12
         if (screenParams.isFragmentScreen()) {
13 13
             return new FragmentScreen(activity, screenParams, titleBarBackButtonListener);
14 14
         } else if (screenParams.hasTopTabs()) {
15
-            return new TabbedScreen(activity, screenParams, titleBarBackButtonListener);
15
+            return new ViewPagerScreen(activity, screenParams, titleBarBackButtonListener);
16 16
         } else {
17 17
             return new SingleScreen(activity, screenParams, titleBarBackButtonListener);
18 18
         }

+ 2
- 9
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java 查看文件

@@ -1,6 +1,5 @@
1 1
 package com.reactnativenavigation.screens;
2 2
 
3
-import android.support.annotation.NonNull;
4 3
 import android.support.v7.app.AppCompatActivity;
5 4
 
6 5
 import com.reactnativenavigation.params.ScreenParams;
@@ -21,17 +20,11 @@ public class SingleScreen extends Screen {
21 20
     @Override
22 21
     protected void createContent() {
23 22
         contentView = new ContentView(getContext(), screenParams.screenId, screenParams.passProps, screenParams.navigationParams, this);
24
-        addView(contentView, addBelowTopBar());
25
-        contentView.init();
26
-    }
27
-
28
-    @NonNull
29
-    private LayoutParams addBelowTopBar() {
30 23
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
31
-        if (!screenParams.styleParams.drawUnderTopBar) {
24
+        if (screenParams.styleParams.drawBelowTopBar) {
32 25
             params.addRule(BELOW, topBar.getId());
33 26
         }
34
-        return params;
27
+        addView(contentView, params);
35 28
     }
36 29
 
37 30
     @Override

android/app/src/main/java/com/reactnativenavigation/screens/TabbedScreen.java → android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java 查看文件

@@ -1,6 +1,5 @@
1 1
 package com.reactnativenavigation.screens;
2 2
 
3
-import android.support.annotation.NonNull;
4 3
 import android.support.design.widget.TabLayout;
5 4
 import android.support.v4.view.PagerAdapter;
6 5
 import android.support.v4.view.ViewPager;
@@ -18,13 +17,13 @@ import java.util.List;
18 17
 
19 18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
20 19
 
21
-public class TabbedScreen extends Screen {
20
+public class ViewPagerScreen extends Screen {
22 21
 
23 22
     private List<ContentView> contentViews;
24 23
     private ViewPager viewPager;
25 24
     private ContentViewPagerAdapter adapter;
26 25
 
27
-    public TabbedScreen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener backButtonListener) {
26
+    public ViewPagerScreen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener backButtonListener) {
28 27
         super(activity, screenParams, backButtonListener);
29 28
     }
30 29
 
@@ -42,8 +41,7 @@ public class TabbedScreen extends Screen {
42 41
                     screenParams.passProps,
43 42
                     screenParams.navigationParams,
44 43
                     this);
45
-            viewPager.addView(contentView, addBelowTopBar());
46
-            contentView.init();
44
+            addContent(contentView);
47 45
             contentViews.add(contentView);
48 46
         }
49 47
 
@@ -52,13 +50,12 @@ public class TabbedScreen extends Screen {
52 50
         tabLayout.setupWithViewPager(viewPager);
53 51
     }
54 52
 
55
-    @NonNull
56
-    private LayoutParams addBelowTopBar() {
53
+    private void addContent(ContentView contentView) {
57 54
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
58
-        if (!screenParams.styleParams.drawUnderTopBar) {
55
+        if (screenParams.styleParams.drawBelowTopBar) {
59 56
             params.addRule(BELOW, topBar.getId());
60 57
         }
61
-        return params;
58
+        viewPager.addView(contentView, params);
62 59
     }
63 60
 
64 61
     @Override

+ 8
- 3
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java 查看文件

@@ -21,10 +21,13 @@ public class ContentView extends ReactRootView {
21 21
         this.screenId = screenId;
22 22
         this.passProps = passProps;
23 23
         this.navigationParams = navigationParams;
24
-        scrollViewAttacher = new ScrollViewAttacher(scrollListener);
24
+        if (scrollListener != null) {
25
+            scrollViewAttacher = new ScrollViewAttacher(scrollListener);
26
+        }
27
+        attachToJS();
25 28
     }
26 29
 
27
-    public void init() {
30
+    private void attachToJS() {
28 31
         ReactInstanceManager react = NavigationApplication.instance.getNavigationReactInstance().getReactInstanceManager();
29 32
         startReactApplication(react, screenId, mergePropsAndNavigationParams());
30 33
     }
@@ -32,7 +35,9 @@ public class ContentView extends ReactRootView {
32 35
     @Override
33 36
     public void onViewAdded(View child) {
34 37
         super.onViewAdded(child);
35
-        scrollViewAttacher.onViewAdded(child);
38
+        if (scrollViewAttacher != null) {
39
+            scrollViewAttacher.onViewAdded(child);
40
+        }
36 41
     }
37 42
 
38 43
     private Bundle mergePropsAndNavigationParams() {