Bläddra i källkod

Change topTabParams to PageParams

TopTabParams are a subset of ScreenParams, moved the properties that
are shared by both classes to BaseScreenParams.
This change was needed to report screen changes properly in ViewPagerScreen
Guy Carmeli 8 år sedan
förälder
incheckning
12684b5418

+ 4
- 4
android/app/src/main/java/com/reactnativenavigation/events/ScreenChangedEvent.java Visa fil

@@ -1,18 +1,18 @@
1 1
 package com.reactnativenavigation.events;
2 2
 
3
+import com.reactnativenavigation.params.BaseScreenParams;
3 4
 import com.reactnativenavigation.params.FabParams;
4
-import com.reactnativenavigation.params.ScreenParams;
5
-import com.reactnativenavigation.params.TopTabParams;
5
+import com.reactnativenavigation.params.PageParams;
6 6
 
7 7
 public class ScreenChangedEvent implements Event {
8 8
     public static final String TYPE = "ScreenChangedEvent";
9 9
     public FabParams fabParams;
10 10
 
11
-    public ScreenChangedEvent(ScreenParams screenParams) {
11
+    public ScreenChangedEvent(BaseScreenParams screenParams) {
12 12
         this.fabParams = screenParams.fabParams;
13 13
     }
14 14
 
15
-    public ScreenChangedEvent(TopTabParams topTabParams) {
15
+    public ScreenChangedEvent(PageParams topTabParams) {
16 16
         this.fabParams = topTabParams.fabParams;
17 17
     }
18 18
 

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Visa fil

@@ -100,6 +100,7 @@ public class SingleScreenLayout extends RelativeLayout implements Layout {
100 100
 
101 101
         if (stack.canPop()) {
102 102
             stack.pop(true);
103
+            EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
103 104
             return true;
104 105
         } else {
105 106
             return false;

+ 36
- 0
android/app/src/main/java/com/reactnativenavigation/params/BaseScreenParams.java Visa fil

@@ -0,0 +1,36 @@
1
+package com.reactnativenavigation.params;
2
+
3
+import android.os.Bundle;
4
+
5
+import java.util.List;
6
+
7
+public class BaseScreenParams {
8
+    public String screenId;
9
+    public String title;
10
+    public NavigationParams navigationParams;
11
+    public List<TitleBarButtonParams> rightButtons;
12
+    public TitleBarLeftButtonParams leftButton;
13
+    public FabParams fabParams;
14
+
15
+    public boolean overrideBackPressInJs;
16
+    public StyleParams styleParams;
17
+    public String fragmentCreatorClassName;
18
+    public Bundle fragmentCreatorPassProps;
19
+    public boolean animateScreenTransitions;
20
+
21
+    public boolean isFragmentScreen() {
22
+        return fragmentCreatorClassName != null;
23
+    }
24
+
25
+    public String getScreenInstanceId() {
26
+        return navigationParams.screenInstanceId;
27
+    }
28
+
29
+    public String getNavigatorId() {
30
+        return navigationParams.navigatorId;
31
+    }
32
+
33
+    public String getNavigatorEventId() {
34
+        return navigationParams.navigatorEventId;
35
+    }
36
+}

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/params/PageParams.java Visa fil

@@ -0,0 +1,6 @@
1
+package com.reactnativenavigation.params;
2
+
3
+public class PageParams extends BaseScreenParams {
4
+
5
+
6
+}

+ 3
- 30
android/app/src/main/java/com/reactnativenavigation/params/ScreenParams.java Visa fil

@@ -1,44 +1,17 @@
1 1
 package com.reactnativenavigation.params;
2 2
 
3 3
 import android.graphics.drawable.Drawable;
4
-import android.os.Bundle;
5 4
 
6 5
 import java.util.List;
7 6
 
8
-public class ScreenParams {
9
-    public String screenId;
10
-    public List<TitleBarButtonParams> rightButtons;
11
-    public TitleBarLeftButtonParams leftButton;
12
-    public boolean overrideBackPressInJs;
13
-    public String title;
14
-    public StyleParams styleParams;
15
-    public List<TopTabParams> topTabParams;
16
-    public String fragmentCreatorClassName;
17
-    public Bundle fragmentCreatorPassProps;
18
-    public boolean animateScreenTransitions;
19
-    public FabParams fabParams;
7
+public class ScreenParams extends BaseScreenParams {
8
+
20 9
     public String tabLabel;
21 10
     public Drawable tabIcon;
22
-
23
-    public NavigationParams navigationParams;
11
+    public List<PageParams> topTabParams;
24 12
 
25 13
     public boolean hasTopTabs() {
26 14
         return topTabParams != null && !topTabParams.isEmpty();
27 15
     }
28 16
 
29
-    public boolean isFragmentScreen() {
30
-        return fragmentCreatorClassName != null;
31
-    }
32
-
33
-    public String getScreenInstanceId() {
34
-        return navigationParams.screenInstanceId;
35
-    }
36
-
37
-    public String getNavigatorId() {
38
-        return navigationParams.navigatorId;
39
-    }
40
-
41
-    public String getNavigatorEventId() {
42
-        return navigationParams.navigatorEventId;
43
-    }
44 17
 }

+ 0
- 12
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java Visa fil

@@ -1,12 +0,0 @@
1
-package com.reactnativenavigation.params;
2
-
3
-import java.util.List;
4
-
5
-public class TopTabParams {
6
-    public String screenId;
7
-    public String title;
8
-    public NavigationParams navigationParams;
9
-    public List<TitleBarButtonParams> rightButtons;
10
-    public TitleBarLeftButtonParams leftButton;
11
-    public FabParams fabParams;
12
-}

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java Visa fil

@@ -5,7 +5,7 @@ import android.os.Bundle;
5 5
 
6 6
 import com.reactnativenavigation.params.NavigationParams;
7 7
 import com.reactnativenavigation.params.ScreenParams;
8
-import com.reactnativenavigation.params.TopTabParams;
8
+import com.reactnativenavigation.params.PageParams;
9 9
 import com.reactnativenavigation.react.ImageLoader;
10 10
 
11 11
 import java.util.List;
@@ -67,8 +67,8 @@ public class ScreenParamsParser extends Parser {
67 67
         return tabLabel;
68 68
     }
69 69
 
70
-    private static List<TopTabParams> parseTopTabs(Bundle params) {
71
-        List<TopTabParams> topTabParams = null;
70
+    private static List<PageParams> parseTopTabs(Bundle params) {
71
+        List<PageParams> topTabParams = null;
72 72
         if (hasKey(params, TOP_TABS)) {
73 73
             topTabParams = new TopTabParamsParser().parse(params.getBundle(TOP_TABS));
74 74
         }

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java Visa fil

@@ -4,7 +4,7 @@ import android.os.Bundle;
4 4
 import android.support.annotation.NonNull;
5 5
 
6 6
 import com.reactnativenavigation.params.NavigationParams;
7
-import com.reactnativenavigation.params.TopTabParams;
7
+import com.reactnativenavigation.params.PageParams;
8 8
 
9 9
 import java.util.List;
10 10
 
@@ -14,18 +14,18 @@ public class TopTabParamsParser extends Parser {
14 14
     private static final String NAVIGATION_PARAMS = "navigationParams";
15 15
 
16 16
     @SuppressWarnings("ConstantConditions")
17
-    public List<TopTabParams> parse(Bundle params) {
18
-        return parseBundle(params, new ParseStrategy<TopTabParams>() {
17
+    public List<PageParams> parse(Bundle params) {
18
+        return parseBundle(params, new ParseStrategy<PageParams>() {
19 19
             @Override
20
-            public TopTabParams parse(Bundle topTabs) {
20
+            public PageParams parse(Bundle topTabs) {
21 21
                 return parseItem(topTabs);
22 22
             }
23 23
         });
24 24
     }
25 25
 
26 26
     @NonNull
27
-    private static TopTabParams parseItem(Bundle params) {
28
-        TopTabParams result = new TopTabParams();
27
+    private static PageParams parseItem(Bundle params) {
28
+        PageParams result = new PageParams();
29 29
         result.screenId = params.getString(KEY_SCREEN_ID);
30 30
         result.title = params.getString(KEY_TITLE);
31 31
         result.navigationParams = new NavigationParams(params.getBundle(NAVIGATION_PARAMS));

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/screens/ContentViewPagerAdapter.java Visa fil

@@ -10,19 +10,19 @@ import com.facebook.react.bridge.WritableMap;
10 10
 import com.reactnativenavigation.NavigationApplication;
11 11
 import com.reactnativenavigation.events.EventBus;
12 12
 import com.reactnativenavigation.events.ScreenChangedEvent;
13
-import com.reactnativenavigation.params.TopTabParams;
13
+import com.reactnativenavigation.params.PageParams;
14 14
 import com.reactnativenavigation.views.ContentView;
15 15
 
16 16
 import java.util.List;
17 17
 
18 18
 public class ContentViewPagerAdapter extends PagerAdapter implements ViewPager.OnPageChangeListener {
19 19
     private List<ContentView> contentViews;
20
-    private List<TopTabParams> topTabParams;
20
+    private List<PageParams> pageParams;
21 21
     private int currentPosition = 0;
22 22
 
23
-    public ContentViewPagerAdapter(List<ContentView> contentViews, List<TopTabParams> topTabParams) {
23
+    public ContentViewPagerAdapter(List<ContentView> contentViews, List<PageParams> pageParams) {
24 24
         this.contentViews = contentViews;
25
-        this.topTabParams = topTabParams;
25
+        this.pageParams = pageParams;
26 26
     }
27 27
 
28 28
     @Override
@@ -42,7 +42,7 @@ public class ContentViewPagerAdapter extends PagerAdapter implements ViewPager.O
42 42
 
43 43
     @Override
44 44
     public CharSequence getPageTitle(int position) {
45
-        return topTabParams.get(position).title;
45
+        return pageParams.get(position).title;
46 46
     }
47 47
 
48 48
     @Override
@@ -53,7 +53,7 @@ public class ContentViewPagerAdapter extends PagerAdapter implements ViewPager.O
53 53
     @Override
54 54
     public void onPageSelected(int position) {
55 55
         currentPosition = position;
56
-        EventBus.instance.post(new ScreenChangedEvent(topTabParams.get(currentPosition)));
56
+        EventBus.instance.post(new ScreenChangedEvent(pageParams.get(currentPosition)));
57 57
         sendTabSelectedEventToJs();
58 58
     }
59 59
 

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Visa fil

@@ -9,6 +9,7 @@ import android.view.Window;
9 9
 import android.widget.RelativeLayout;
10 10
 
11 11
 import com.reactnativenavigation.animation.VisibilityAnimator;
12
+import com.reactnativenavigation.params.BaseScreenParams;
12 13
 import com.reactnativenavigation.params.ScreenParams;
13 14
 import com.reactnativenavigation.params.StyleParams;
14 15
 import com.reactnativenavigation.params.TitleBarButtonParams;
@@ -132,7 +133,7 @@ public abstract class Screen extends RelativeLayout {
132 133
         return screenParams.getNavigatorEventId();
133 134
     }
134 135
 
135
-    public ScreenParams getScreenParams() {
136
+    public BaseScreenParams getScreenParams() {
136 137
         return screenParams;
137 138
     }
138 139
 

+ 8
- 2
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Visa fil

@@ -4,8 +4,9 @@ import android.support.design.widget.TabLayout;
4 4
 import android.support.v4.view.ViewPager;
5 5
 import android.support.v7.app.AppCompatActivity;
6 6
 
7
+import com.reactnativenavigation.params.BaseScreenParams;
7 8
 import com.reactnativenavigation.params.ScreenParams;
8
-import com.reactnativenavigation.params.TopTabParams;
9
+import com.reactnativenavigation.params.PageParams;
9 10
 import com.reactnativenavigation.views.ContentView;
10 11
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
11 12
 
@@ -24,6 +25,11 @@ public class ViewPagerScreen extends Screen {
24 25
         super(activity, screenParams, backButtonListener);
25 26
     }
26 27
 
28
+    @Override
29
+    public BaseScreenParams getScreenParams() {
30
+        return screenParams.topTabParams.get(viewPager.getCurrentItem());
31
+    }
32
+
27 33
     @Override
28 34
     protected void createContent() {
29 35
         TabLayout tabLayout = topBar.initTabs();
@@ -44,7 +50,7 @@ public class ViewPagerScreen extends Screen {
44 50
 
45 51
     private void addPages() {
46 52
         contentViews = new ArrayList<>();
47
-        for (TopTabParams tab : screenParams.topTabParams) {
53
+        for (PageParams tab : screenParams.topTabParams) {
48 54
             ContentView contentView = new ContentView(getContext(), tab.screenId, tab.navigationParams);
49 55
             addContent(contentView);
50 56
             contentViews.add(contentView);