浏览代码

Set BottomTab style after TitleBar back button click

Guy Carmeli 8 年前
父节点
当前提交
aa2ce1c432

+ 7
- 3
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java 查看文件

@@ -19,6 +19,8 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
19 19
 
20 20
     private final AppCompatActivity activity;
21 21
     private final OnModalDismissedListener onModalDismissedListener;
22
+    private final ScreenParams screenParams;
23
+    private Layout layout;
22 24
 
23 25
     public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
24 26
         layout.setTopBarVisible(screenInstanceId, hidden, animated);
@@ -36,13 +38,15 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
36 38
         layout.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButton);
37 39
     }
38 40
 
41
+    @Override
42
+    public void onTitleBarBackPress() {
43
+        layout.onTitleBarBackPress();
44
+    }
45
+
39 46
     public interface OnModalDismissedListener {
40 47
         void onModalDismissed(Modal modal);
41 48
     }
42 49
 
43
-    private final ScreenParams screenParams;
44
-    private Layout layout;
45
-
46 50
     public Modal(AppCompatActivity activity, OnModalDismissedListener onModalDismissedListener, ScreenParams screenParams) {
47 51
         super(activity, R.style.Modal);
48 52
         this.activity = activity;

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java 查看文件

@@ -96,4 +96,9 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
96 96
             modal.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButton);
97 97
         }
98 98
     }
99
+
100
+    @Override
101
+    public void onTitleBarBackPress() {
102
+        // Do nothing and let the layout handle the back press
103
+    }
99 104
 }

+ 10
- 2
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java 查看文件

@@ -47,7 +47,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
47 47
     }
48 48
 
49 49
     private void createAndAddScreenStack(int position) {
50
-        ScreenStack newStack = new ScreenStack(activity, params.tabParams.get(position));
50
+        ScreenStack newStack = new ScreenStack(activity, params.tabParams.get(position), this);
51 51
         screenStacks[position] = newStack;
52 52
         newStack.setVisibility(INVISIBLE);
53 53
         LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
@@ -138,7 +138,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
138 138
         currentScreenStack.destroy();
139 139
         removeView(currentScreenStack);
140 140
 
141
-        ScreenStack newStack = new ScreenStack(activity, params);
141
+        ScreenStack newStack = new ScreenStack(activity, params, this);
142 142
         screenStacks[currentStackIndex] = newStack;
143 143
         addView(newStack, 0, new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
144 144
 
@@ -180,4 +180,12 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
180 180
     private void setBottomTabsStyleFromCurrentScreen() {
181 181
         bottomTabs.setStyleFromScreen(getCurrentScreenStack().getCurrentScreenStyleParams());
182 182
     }
183
+
184
+    @Override
185
+    public void onTitleBarBackPress() {
186
+        if (getCurrentScreenStack().canPop()) {
187
+            getCurrentScreenStack().pop();
188
+            setBottomTabsStyleFromCurrentScreen();
189
+        }
190
+    }
183 191
 }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStackContainer.java 查看文件

@@ -1,8 +1,9 @@
1 1
 package com.reactnativenavigation.layouts;
2 2
 
3 3
 import com.reactnativenavigation.params.ScreenParams;
4
+import com.reactnativenavigation.views.TitleBarBackButtonListener;
4 5
 
5
-public interface ScreenStackContainer {
6
+public interface ScreenStackContainer extends TitleBarBackButtonListener {
6 7
     void push(ScreenParams screenParams);
7 8
 
8 9
     void pop(ScreenParams screenParams);

+ 8
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java 查看文件

@@ -31,7 +31,7 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
31 31
             stack.destroy();
32 32
             removeView(stack);
33 33
         }
34
-        stack = new ScreenStack(activity, screenParams);
34
+        stack = new ScreenStack(activity, screenParams, this);
35 35
         addView(stack, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
36 36
     }
37 37
 
@@ -95,4 +95,11 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
95 95
     public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams) {
96 96
         stack.setScreenTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButtonParams);
97 97
     }
98
+
99
+    @Override
100
+    public void onTitleBarBackPress() {
101
+        if (stack.canPop()) {
102
+            stack.pop();
103
+        }
104
+    }
98 105
 }

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

@@ -18,14 +18,16 @@ import java.util.Stack;
18 18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
19 19
 
20 20
 // TODO there's really no reason for ScreenStack to extend FrameLayout. All screens can be added to parent.
21
-public class ScreenStack extends FrameLayout implements TitleBarBackButtonListener {
21
+public class ScreenStack extends FrameLayout {
22 22
 
23 23
     private final AppCompatActivity activity;
24
+    private TitleBarBackButtonListener titleBarBackButtonListener;
24 25
     private Stack<Screen> stack = new Stack<>();
25 26
 
26
-    public ScreenStack(AppCompatActivity activity, ScreenParams initialScreenParams) {
27
+    public ScreenStack(AppCompatActivity activity, ScreenParams initialScreenParams, TitleBarBackButtonListener titleBarBackButtonListener) {
27 28
         super(activity);
28 29
         this.activity = activity;
30
+        this.titleBarBackButtonListener = titleBarBackButtonListener;
29 31
         setLayoutTransition(new LayoutTransition());
30 32
         pushInitialScreen(initialScreenParams);
31 33
     }
@@ -41,7 +43,7 @@ public class ScreenStack extends FrameLayout implements TitleBarBackButtonListen
41 43
     }
42 44
 
43 45
     private void addScreen(ScreenParams screenParams) {
44
-        Screen screen = ScreenFactory.create(activity, screenParams, this);
46
+        Screen screen = ScreenFactory.create(activity, screenParams, titleBarBackButtonListener);
45 47
         addView(screen, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
46 48
         stack.push(screen);
47 49
     }
@@ -131,18 +133,11 @@ public class ScreenStack extends FrameLayout implements TitleBarBackButtonListen
131 133
         performOnScreen(screenInstanceId, new Task<Screen>() {
132 134
             @Override
133 135
             public void run(Screen param) {
134
-                param.setTitleBarLeftButton(navigatorEventId, ScreenStack.this, titleBarLeftButtonParams);
136
+                param.setTitleBarLeftButton(navigatorEventId, titleBarBackButtonListener, titleBarLeftButtonParams);
135 137
             }
136 138
         });
137 139
     }
138 140
 
139
-    @Override
140
-    public void onTitleBarBackPress() {
141
-        if (canPop()) {
142
-            pop();
143
-        }
144
-    }
145
-
146 141
     public StyleParams getCurrentScreenStyleParams() {
147 142
         return stack.peek().getStyleParams();
148 143
     }