Browse Source

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 years ago
parent
commit
12684b5418

+ 4
- 4
android/app/src/main/java/com/reactnativenavigation/events/ScreenChangedEvent.java View File

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

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java View File

100
 
100
 
101
         if (stack.canPop()) {
101
         if (stack.canPop()) {
102
             stack.pop(true);
102
             stack.pop(true);
103
+            EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
103
             return true;
104
             return true;
104
         } else {
105
         } else {
105
             return false;
106
             return false;

+ 36
- 0
android/app/src/main/java/com/reactnativenavigation/params/BaseScreenParams.java View File

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 View File

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 View File

1
 package com.reactnativenavigation.params;
1
 package com.reactnativenavigation.params;
2
 
2
 
3
 import android.graphics.drawable.Drawable;
3
 import android.graphics.drawable.Drawable;
4
-import android.os.Bundle;
5
 
4
 
6
 import java.util.List;
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
     public String tabLabel;
9
     public String tabLabel;
21
     public Drawable tabIcon;
10
     public Drawable tabIcon;
22
-
23
-    public NavigationParams navigationParams;
11
+    public List<PageParams> topTabParams;
24
 
12
 
25
     public boolean hasTopTabs() {
13
     public boolean hasTopTabs() {
26
         return topTabParams != null && !topTabParams.isEmpty();
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 View File

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 View File

5
 
5
 
6
 import com.reactnativenavigation.params.NavigationParams;
6
 import com.reactnativenavigation.params.NavigationParams;
7
 import com.reactnativenavigation.params.ScreenParams;
7
 import com.reactnativenavigation.params.ScreenParams;
8
-import com.reactnativenavigation.params.TopTabParams;
8
+import com.reactnativenavigation.params.PageParams;
9
 import com.reactnativenavigation.react.ImageLoader;
9
 import com.reactnativenavigation.react.ImageLoader;
10
 
10
 
11
 import java.util.List;
11
 import java.util.List;
67
         return tabLabel;
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
         if (hasKey(params, TOP_TABS)) {
72
         if (hasKey(params, TOP_TABS)) {
73
             topTabParams = new TopTabParamsParser().parse(params.getBundle(TOP_TABS));
73
             topTabParams = new TopTabParamsParser().parse(params.getBundle(TOP_TABS));
74
         }
74
         }

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java View File

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

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/screens/ContentViewPagerAdapter.java View File

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

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java View File

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

+ 8
- 2
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java View File

4
 import android.support.v4.view.ViewPager;
4
 import android.support.v4.view.ViewPager;
5
 import android.support.v7.app.AppCompatActivity;
5
 import android.support.v7.app.AppCompatActivity;
6
 
6
 
7
+import com.reactnativenavigation.params.BaseScreenParams;
7
 import com.reactnativenavigation.params.ScreenParams;
8
 import com.reactnativenavigation.params.ScreenParams;
8
-import com.reactnativenavigation.params.TopTabParams;
9
+import com.reactnativenavigation.params.PageParams;
9
 import com.reactnativenavigation.views.ContentView;
10
 import com.reactnativenavigation.views.ContentView;
10
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
11
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
11
 
12
 
24
         super(activity, screenParams, backButtonListener);
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
     @Override
33
     @Override
28
     protected void createContent() {
34
     protected void createContent() {
29
         TabLayout tabLayout = topBar.initTabs();
35
         TabLayout tabLayout = topBar.initTabs();
44
 
50
 
45
     private void addPages() {
51
     private void addPages() {
46
         contentViews = new ArrayList<>();
52
         contentViews = new ArrayList<>();
47
-        for (TopTabParams tab : screenParams.topTabParams) {
53
+        for (PageParams tab : screenParams.topTabParams) {
48
             ContentView contentView = new ContentView(getContext(), tab.screenId, tab.navigationParams);
54
             ContentView contentView = new ContentView(getContext(), tab.screenId, tab.navigationParams);
49
             addContent(contentView);
55
             addContent(contentView);
50
             contentViews.add(contentView);
56
             contentViews.add(contentView);