소스 검색

Fix selectedTab event

Guy Carmeli 8 년 전
부모
커밋
8b580ca2a9

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java 파일 보기

@@ -65,7 +65,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
65 65
 
66 66
     private void createAndAddScreens(int position) {
67 67
         ScreenParams screenParams = params.tabParams.get(position);
68
-        ScreenStack newStack = new ScreenStack(activity, getScreenStackParent(), screenParams.navigatorId, this);
68
+        ScreenStack newStack = new ScreenStack(activity, getScreenStackParent(), screenParams.getNavigatorId(), this);
69 69
         newStack.pushInitialScreen(screenParams, createScreenLayoutParams(screenParams));
70 70
         screenStacks[position] = newStack;
71 71
     }
@@ -166,7 +166,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
166 166
 
167 167
     @Override
168 168
     public void push(ScreenParams screenParams) {
169
-        ScreenStack screenStack = getScreenStack(screenParams.navigatorId);
169
+        ScreenStack screenStack = getScreenStack(screenParams.getNavigatorId());
170 170
         if (screenStack == null) {
171 171
             return;
172 172
         }
@@ -201,7 +201,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
201 201
         currentScreenStack.destroy();
202 202
         removeView(currentScreenStack.peek());
203 203
 
204
-        ScreenStack newStack = new ScreenStack(activity, getScreenStackParent(), params.navigatorId, this);
204
+        ScreenStack newStack = new ScreenStack(activity, getScreenStackParent(), params.getNavigatorId(), this);
205 205
         LayoutParams lp = createScreenLayoutParams(params);
206 206
         newStack.pushInitialScreen(params, lp);
207 207
         screenStacks[currentStackIndex] = newStack;

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java 파일 보기

@@ -60,7 +60,7 @@ public class SingleScreenLayout extends RelativeLayout implements Layout {
60 60
         if (stack != null) {
61 61
             stack.destroy();
62 62
         }
63
-        stack = new ScreenStack(activity, parent, screenParams.navigatorId, this);
63
+        stack = new ScreenStack(activity, parent, screenParams.getNavigatorId(), this);
64 64
         LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
65 65
         stack.pushInitialScreen(screenParams, lp);
66 66
         stack.show();

+ 27
- 0
android/app/src/main/java/com/reactnativenavigation/params/NavigationParams.java 파일 보기

@@ -0,0 +1,27 @@
1
+package com.reactnativenavigation.params;
2
+
3
+import android.os.Bundle;
4
+
5
+public class NavigationParams {
6
+    public static final String SCREEN_INSTANCE_ID = "screenInstanceID";
7
+    public static final String NAVIGATOR_ID = "navigatorID";
8
+    public static final String NAVIGATOR_EVENT_ID = "navigatorEventID";
9
+
10
+    public String screenInstanceId;
11
+    public String navigatorId;
12
+    public String navigatorEventId;
13
+
14
+    public NavigationParams(Bundle bundle) {
15
+        screenInstanceId = bundle.getString(SCREEN_INSTANCE_ID);
16
+        navigatorId = bundle.getString(NAVIGATOR_ID);
17
+        navigatorEventId = bundle.getString(NAVIGATOR_EVENT_ID);
18
+    }
19
+
20
+    public Bundle toBundle() {
21
+        Bundle b = new Bundle();
22
+        b.putString(SCREEN_INSTANCE_ID, screenInstanceId);
23
+        b.putString(NAVIGATOR_ID, navigatorId);
24
+        b.putString(NAVIGATOR_EVENT_ID, navigatorEventId);
25
+        return b;
26
+    }
27
+}

+ 13
- 4
android/app/src/main/java/com/reactnativenavigation/params/ScreenParams.java 파일 보기

@@ -20,10 +20,7 @@ public class ScreenParams {
20 20
     public String tabLabel;
21 21
     public Drawable tabIcon;
22 22
 
23
-    public String screenInstanceId;
24
-    public String navigatorEventId;
25
-    public String navigatorId;
26
-    public Bundle navigationParams;
23
+    public NavigationParams navigationParams;
27 24
 
28 25
     public boolean hasTopTabs() {
29 26
         return topTabParams != null && !topTabParams.isEmpty();
@@ -32,4 +29,16 @@ public class ScreenParams {
32 29
     public boolean isFragmentScreen() {
33 30
         return fragmentCreatorClassName != null;
34 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
+    }
35 44
 }

+ 1
- 3
android/app/src/main/java/com/reactnativenavigation/params/SideMenuParams.java 파일 보기

@@ -1,9 +1,7 @@
1 1
 package com.reactnativenavigation.params;
2 2
 
3
-import android.os.Bundle;
4
-
5 3
 public class SideMenuParams {
6 4
     public String screenId;
7
-    public Bundle navigationParams;
5
+    public NavigationParams navigationParams;
8 6
     public boolean disableOpenGesture;
9 7
 }

+ 1
- 3
android/app/src/main/java/com/reactnativenavigation/params/TopTabParams.java 파일 보기

@@ -1,9 +1,7 @@
1 1
 package com.reactnativenavigation.params;
2 2
 
3
-import android.os.Bundle;
4
-
5 3
 public class TopTabParams {
6 4
     public String screenId;
7 5
     public String title;
8
-    public Bundle navigationParams;
6
+    public NavigationParams navigationParams;
9 7
 }

+ 2
- 8
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java 파일 보기

@@ -3,6 +3,7 @@ package com.reactnativenavigation.params.parsers;
3 3
 import android.graphics.drawable.Drawable;
4 4
 import android.os.Bundle;
5 5
 
6
+import com.reactnativenavigation.params.NavigationParams;
6 7
 import com.reactnativenavigation.params.ScreenParams;
7 8
 import com.reactnativenavigation.params.TitleBarButtonParams;
8 9
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
@@ -15,9 +16,6 @@ import java.util.List;
15 16
 public class ScreenParamsParser extends Parser {
16 17
     private static final String KEY_TITLE = "title";
17 18
     private static final String KEY_SCREEN_ID = "screenId";
18
-    private static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
19
-    private static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
20
-    private static final String KEY_NAVIGATOR_ID = "navigatorID";
21 19
     private static final String KEY_NAVIGATION_PARAMS = "navigationParams";
22 20
     private static final String KEY_RIGHT_BUTTONS = "rightButtons";
23 21
     private static final String KEY_LEFT_BUTTON = "leftButton";
@@ -32,12 +30,8 @@ public class ScreenParamsParser extends Parser {
32 30
     public static ScreenParams parse(Bundle params) {
33 31
         ScreenParams result = new ScreenParams();
34 32
         result.screenId = params.getString(KEY_SCREEN_ID);
35
-        result.screenInstanceId = params.getString(KEY_SCREEN_INSTANCE_ID);
36 33
         assertKeyExists(params, KEY_NAVIGATION_PARAMS);
37
-        result.navigationParams = params.getBundle(KEY_NAVIGATION_PARAMS);
38
-        result.navigatorEventId = result.navigationParams.getString(KEY_NAVIGATOR_EVENT_ID);
39
-        result.navigatorId = result.navigationParams.getString(KEY_NAVIGATOR_ID);
40
-        result.screenInstanceId = result.navigationParams.getString(KEY_SCREEN_INSTANCE_ID);
34
+        result.navigationParams = new NavigationParams(params.getBundle(KEY_NAVIGATION_PARAMS));
41 35
 
42 36
         result.styleParams = new StyleParamsParser(params.getBundle(STYLE_PARAMS)).parse();
43 37
 

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/SideMenuParamsParser.java 파일 보기

@@ -2,6 +2,7 @@ package com.reactnativenavigation.params.parsers;
2 2
 
3 3
 import android.os.Bundle;
4 4
 
5
+import com.reactnativenavigation.params.NavigationParams;
5 6
 import com.reactnativenavigation.params.SideMenuParams;
6 7
 
7 8
 public class SideMenuParamsParser extends Parser {
@@ -9,7 +10,7 @@ public class SideMenuParamsParser extends Parser {
9 10
     public static SideMenuParams parse(Bundle sideMenu) {
10 11
         SideMenuParams result = new SideMenuParams();
11 12
         result.screenId = sideMenu.getString("screenId");
12
-        result.navigationParams = sideMenu.getBundle("navigationParams");
13
+        result.navigationParams = new NavigationParams(sideMenu.getBundle("navigationParams"));
13 14
         result.disableOpenGesture = sideMenu.getBoolean("disableOpenGesture", false);
14 15
         return result;
15 16
     }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java 파일 보기

@@ -3,6 +3,7 @@ package com.reactnativenavigation.params.parsers;
3 3
 import android.os.Bundle;
4 4
 import android.support.annotation.NonNull;
5 5
 
6
+import com.reactnativenavigation.params.NavigationParams;
6 7
 import com.reactnativenavigation.params.TopTabParams;
7 8
 
8 9
 import java.util.ArrayList;
@@ -27,7 +28,7 @@ public class TopTabParamsParser extends Parser {
27 28
         TopTabParams result = new TopTabParams();
28 29
         result.screenId = params.getString(KEY_SCREEN_ID);
29 30
         result.title = params.getString(KEY_TITLE);
30
-        result.navigationParams = params.getBundle(NAVIGATION_PARAMS);
31
+        result.navigationParams = new NavigationParams(params.getBundle(NAVIGATION_PARAMS));
31 32
         return result;
32 33
     }
33 34
 }

+ 1
- 2
android/app/src/main/java/com/reactnativenavigation/screens/ContentViewPagerAdapter.java 파일 보기

@@ -40,8 +40,7 @@ public class ContentViewPagerAdapter extends PagerAdapter {
40 40
     private void sendPageChangeEvent() {
41 41
         WritableMap data = Arguments.createMap();
42 42
         String navigatorEventId = contentViews.get(currentPosition).getNavigatorEventId();
43
-        data.putInt("position", currentPosition);
44
-        NavigationApplication.instance.sendNavigatorEvent("selectedTabChanged", navigatorEventId, data);
43
+        NavigationApplication.instance.sendNavigatorEvent("tabSelected", navigatorEventId, data);
45 44
     }
46 45
 
47 46
     @Override

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java 파일 보기

@@ -73,7 +73,7 @@ public abstract class Screen extends RelativeLayout {
73 73
         topBar.addTitleBarAndSetButtons(screenParams.rightButtons,
74 74
                 screenParams.leftButton,
75 75
                 leftButtonOnClickListener,
76
-                screenParams.navigatorEventId,
76
+                screenParams.getNavigatorEventId(),
77 77
                 screenParams.overrideBackPressInJs);
78 78
     }
79 79
 
@@ -129,7 +129,7 @@ public abstract class Screen extends RelativeLayout {
129 129
     public abstract void preventMountAfterReattachedToWindow();
130 130
 
131 131
     public String getScreenInstanceId() {
132
-        return screenParams.screenInstanceId;
132
+        return screenParams.getScreenInstanceId();
133 133
     }
134 134
 
135 135
     public void setTopBarVisible(boolean visible, boolean animate) {

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java 파일 보기

@@ -211,7 +211,7 @@ public class ScreenStack {
211 211
     public boolean handleBackPressInJs() {
212 212
         ScreenParams currentScreen = stack.peek().screenParams;
213 213
         if (currentScreen.overrideBackPressInJs) {
214
-            NavigationApplication.instance.sendNavigatorEvent("backPress", currentScreen.navigatorEventId);
214
+            NavigationApplication.instance.sendNavigatorEvent("backPress", currentScreen.getNavigatorEventId());
215 215
             return true;
216 216
         }
217 217
         return false;

+ 6
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java 파일 보기

@@ -45,7 +45,7 @@ public class ViewPagerScreen extends Screen {
45 45
     private void addPages() {
46 46
         contentViews = new ArrayList<>();
47 47
         for (TopTabParams tab : screenParams.topTabParams) {
48
-            ContentView contentView = new ContentView(getContext(), tab.screenId, tab.navigationParams, screenParams.navigatorEventId);
48
+            ContentView contentView = new ContentView(getContext(), tab.screenId, tab.navigationParams);
49 49
             addContent(contentView);
50 50
             contentViews.add(contentView);
51 51
         }
@@ -87,4 +87,9 @@ public class ViewPagerScreen extends Screen {
87 87
     public void setOnDisplayListener(OnDisplayListener onContentViewDisplayedListener) {
88 88
         contentViews.get(0).setOnDisplayListener(onContentViewDisplayedListener);
89 89
     }
90
+
91
+    @Override
92
+    public String getScreenInstanceId() {
93
+        return screenParams.topTabParams.get(viewPager.getCurrentItem()).navigationParams.screenInstanceId;
94
+    }
90 95
 }

+ 6
- 11
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java 파일 보기

@@ -1,11 +1,11 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4
-import android.os.Bundle;
5 4
 import android.view.View;
6 5
 
7 6
 import com.facebook.react.ReactRootView;
8 7
 import com.reactnativenavigation.NavigationApplication;
8
+import com.reactnativenavigation.params.NavigationParams;
9 9
 import com.reactnativenavigation.react.ReactViewHacks;
10 10
 import com.reactnativenavigation.screens.SingleScreen;
11 11
 import com.reactnativenavigation.utils.ViewUtils;
@@ -13,26 +13,20 @@ import com.reactnativenavigation.utils.ViewUtils;
13 13
 public class ContentView extends ReactRootView {
14 14
 
15 15
     private final String screenId;
16
-    private String navigatorEventId;
17
-    private final Bundle navigationParams;
16
+    private final NavigationParams navigationParams;
18 17
 
19 18
     boolean isContentVisible = false;
20 19
     private SingleScreen.OnDisplayListener onDisplayListener;
21 20
 
22
-    public ContentView(Context context, String screenId, Bundle navigationParams) {
23
-        this(context, screenId, navigationParams, null);
24
-    }
25
-
26
-    public ContentView(Context context, String screenId, Bundle navigationParams, String navigatorEventId) {
21
+    public ContentView(Context context, String screenId, NavigationParams navigationParams) {
27 22
         super(context);
28 23
         this.screenId = screenId;
29
-        this.navigatorEventId = navigatorEventId;
30 24
         this.navigationParams = navigationParams;
31 25
         attachToJS();
32 26
     }
33 27
 
34 28
     public String getNavigatorEventId() {
35
-        return navigatorEventId;
29
+        return navigationParams.navigatorEventId;
36 30
     }
37 31
 
38 32
     public void preventUnmountOnDetachedFromWindow() {
@@ -69,7 +63,8 @@ public class ContentView extends ReactRootView {
69 63
     }
70 64
 
71 65
     private void attachToJS() {
72
-        startReactApplication(NavigationApplication.instance.getReactGateway().getReactInstanceManager(), screenId, navigationParams);
66
+        startReactApplication(NavigationApplication.instance.getReactGateway().getReactInstanceManager(), screenId,
67
+                navigationParams.toBundle());
73 68
     }
74 69
 
75 70
     public void setOnDisplayListener(SingleScreen.OnDisplayListener onDisplayListener) {