Daniel Zlotin 8 年 前
コミット
60cca6908b
共有18 個のファイルを変更した116 個の追加67 個の削除を含む
  1. 3
    0
      android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java
  2. 14
    1
      android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java
  3. 10
    0
      android/app/src/main/java/com/reactnativenavigation/events/ModalDismissedEvent.java
  4. 4
    4
      android/app/src/main/java/com/reactnativenavigation/events/ScreenChangedEvent.java
  5. 5
    0
      android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java
  6. 2
    0
      android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java
  7. 6
    0
      android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java
  8. 36
    0
      android/app/src/main/java/com/reactnativenavigation/params/BaseScreenParams.java
  9. 6
    0
      android/app/src/main/java/com/reactnativenavigation/params/PageParams.java
  10. 3
    30
      android/app/src/main/java/com/reactnativenavigation/params/ScreenParams.java
  11. 0
    12
      android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java
  12. 3
    3
      android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java
  13. 6
    6
      android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java
  14. 6
    6
      android/app/src/main/java/com/reactnativenavigation/screens/ContentViewPagerAdapter.java
  15. 2
    1
      android/app/src/main/java/com/reactnativenavigation/screens/Screen.java
  16. 8
    2
      android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java
  17. 1
    1
      example-redux/README.md
  18. 1
    1
      package.json

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java ファイルの表示

@@ -2,6 +2,8 @@ package com.reactnativenavigation.controllers;
2 2
 
3 3
 import android.support.v7.app.AppCompatActivity;
4 4
 
5
+import com.reactnativenavigation.events.EventBus;
6
+import com.reactnativenavigation.events.ModalDismissedEvent;
5 7
 import com.reactnativenavigation.layouts.ScreenStackContainer;
6 8
 import com.reactnativenavigation.params.ScreenParams;
7 9
 import com.reactnativenavigation.params.TitleBarButtonParams;
@@ -72,6 +74,7 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
72 74
     @Override
73 75
     public void onModalDismissed(Modal modal) {
74 76
         stack.remove(modal);
77
+        EventBus.instance.post(new ModalDismissedEvent());
75 78
     }
76 79
 
77 80
     public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {

+ 14
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java ファイルの表示

@@ -7,6 +7,10 @@ import android.view.KeyEvent;
7 7
 
8 8
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
9 9
 import com.reactnativenavigation.NavigationApplication;
10
+import com.reactnativenavigation.events.Event;
11
+import com.reactnativenavigation.events.EventBus;
12
+import com.reactnativenavigation.events.ModalDismissedEvent;
13
+import com.reactnativenavigation.events.Subscriber;
10 14
 import com.reactnativenavigation.layouts.BottomTabsLayout;
11 15
 import com.reactnativenavigation.layouts.Layout;
12 16
 import com.reactnativenavigation.layouts.LayoutFactory;
@@ -21,7 +25,7 @@ import com.reactnativenavigation.react.RedboxPermission;
21 25
 
22 26
 import java.util.List;
23 27
 
24
-public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, ReactGateway.OnJsDevReloadListener {
28
+public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, ReactGateway.OnJsDevReloadListener, Subscriber {
25 29
 
26 30
     /**
27 31
      * Although we start multiple activities, we make sure to pass Intent.CLEAR_TASK | Intent.NEW_TASK
@@ -79,6 +83,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
79 83
 
80 84
         currentActivity = this;
81 85
         NavigationApplication.instance.getReactGateway().onResumeActivity(this, this, this);
86
+        EventBus.instance.register(this);
82 87
     }
83 88
 
84 89
     @Override
@@ -86,6 +91,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
86 91
         super.onPause();
87 92
         currentActivity = null;
88 93
         NavigationApplication.instance.getReactGateway().onPauseActivity();
94
+        EventBus.instance.unregister(this);
89 95
     }
90 96
 
91 97
     @Override
@@ -249,4 +255,11 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
249 255
     public void showSnackbar(SnackbarParams params) {
250 256
         layout.showSnackbar(params);
251 257
     }
258
+
259
+    @Override
260
+    public void onEvent(Event event) {
261
+        if (event.getType() == ModalDismissedEvent.TYPE) {
262
+            layout.onModalDismissed();
263
+        }
264
+    }
252 265
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/events/ModalDismissedEvent.java ファイルの表示

@@ -0,0 +1,10 @@
1
+package com.reactnativenavigation.events;
2
+
3
+public class ModalDismissedEvent implements Event {
4
+    public static final String TYPE = "ModalDismissedEvent";
5
+
6
+    @Override
7
+    public String getType() {
8
+        return TYPE;
9
+    }
10
+}

+ 4
- 4
android/app/src/main/java/com/reactnativenavigation/events/ScreenChangedEvent.java ファイルの表示

@@ -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
 

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java ファイルの表示

@@ -193,6 +193,11 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
193 193
         snackbarAndFabContainer.showSnackbar(eventId, params);
194 194
     }
195 195
 
196
+    @Override
197
+    public void onModalDismissed() {
198
+        EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
199
+    }
200
+
196 201
     public void selectBottomTabByTabIndex(Integer index) {
197 202
         bottomTabs.setCurrentItem(index);
198 203
     }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java ファイルの表示

@@ -28,4 +28,6 @@ public interface Layout extends ScreenStackContainer {
28 28
     void setSideMenuVisible(boolean animated, boolean visible);
29 29
 
30 30
     void showSnackbar(SnackbarParams params);
31
+
32
+    void onModalDismissed();
31 33
 }

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java ファイルの表示

@@ -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;
@@ -192,6 +193,11 @@ public class SingleScreenLayout extends RelativeLayout implements Layout {
192 193
         snackbarAndFabContainer.showSnackbar(navigatorEventId, params);
193 194
     }
194 195
 
196
+    @Override
197
+    public void onModalDismissed() {
198
+        EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
199
+    }
200
+
195 201
     @Override
196 202
     public boolean onTitleBarBackButtonClick() {
197 203
         if (leftButtonOnClickListener != null) {

+ 36
- 0
android/app/src/main/java/com/reactnativenavigation/params/BaseScreenParams.java ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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);

+ 1
- 1
example-redux/README.md ファイルの表示

@@ -4,7 +4,7 @@ A simple usage example for an app based on redux. If you're not using redux, tak
4 4
 
5 5
 ## Installation - iOS
6 6
 
7
-* In the `example/` folder, run `npm install`
7
+* In the `example-redux/` folder, run `npm install`
8 8
 
9 9
 > Make sure you're using npm ver 3. If you normally use npm ver 2 on your system and reluctant to upgrade, you can install [npm 3 alongside 2](https://www.npmjs.com/package/npm3). For more details see https://github.com/wix/react-native-navigation/issues/1. In addition, redux also causes some issues with npm 2. If you have to use npm 2 on this project, fix those by running `npm run fix_npm2` in your project directory after running `npm install`.
10 10
 

+ 1
- 1
package.json ファイルの表示

@@ -7,7 +7,7 @@
7 7
     "type": "git",
8 8
     "url": "https://github.com/wix/react-native-navigation.git"
9 9
   },
10
-  "version": "2.0.0-experimental.96",
10
+  "version": "2.0.0-experimental.97",
11 11
   "description": "React Native Navigation - truly native navigation for iOS and Android",
12 12
   "nativePackage": true,
13 13
   "bugs": {