Browse Source

Set BottomTab style after TitleBar back button click

Guy Carmeli 8 years ago
parent
commit
aa2ce1c432

+ 7
- 3
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java View File

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

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java View File

96
             modal.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButton);
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 View File

47
     }
47
     }
48
 
48
 
49
     private void createAndAddScreenStack(int position) {
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
         screenStacks[position] = newStack;
51
         screenStacks[position] = newStack;
52
         newStack.setVisibility(INVISIBLE);
52
         newStack.setVisibility(INVISIBLE);
53
         LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
53
         LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
138
         currentScreenStack.destroy();
138
         currentScreenStack.destroy();
139
         removeView(currentScreenStack);
139
         removeView(currentScreenStack);
140
 
140
 
141
-        ScreenStack newStack = new ScreenStack(activity, params);
141
+        ScreenStack newStack = new ScreenStack(activity, params, this);
142
         screenStacks[currentStackIndex] = newStack;
142
         screenStacks[currentStackIndex] = newStack;
143
         addView(newStack, 0, new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
143
         addView(newStack, 0, new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
144
 
144
 
180
     private void setBottomTabsStyleFromCurrentScreen() {
180
     private void setBottomTabsStyleFromCurrentScreen() {
181
         bottomTabs.setStyleFromScreen(getCurrentScreenStack().getCurrentScreenStyleParams());
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 View File

1
 package com.reactnativenavigation.layouts;
1
 package com.reactnativenavigation.layouts;
2
 
2
 
3
 import com.reactnativenavigation.params.ScreenParams;
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
     void push(ScreenParams screenParams);
7
     void push(ScreenParams screenParams);
7
 
8
 
8
     void pop(ScreenParams screenParams);
9
     void pop(ScreenParams screenParams);

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

31
             stack.destroy();
31
             stack.destroy();
32
             removeView(stack);
32
             removeView(stack);
33
         }
33
         }
34
-        stack = new ScreenStack(activity, screenParams);
34
+        stack = new ScreenStack(activity, screenParams, this);
35
         addView(stack, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
35
         addView(stack, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
36
     }
36
     }
37
 
37
 
95
     public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams) {
95
     public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams) {
96
         stack.setScreenTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButtonParams);
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 View File

18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
19
 
19
 
20
 // TODO there's really no reason for ScreenStack to extend FrameLayout. All screens can be added to parent.
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
     private final AppCompatActivity activity;
23
     private final AppCompatActivity activity;
24
+    private TitleBarBackButtonListener titleBarBackButtonListener;
24
     private Stack<Screen> stack = new Stack<>();
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
         super(activity);
28
         super(activity);
28
         this.activity = activity;
29
         this.activity = activity;
30
+        this.titleBarBackButtonListener = titleBarBackButtonListener;
29
         setLayoutTransition(new LayoutTransition());
31
         setLayoutTransition(new LayoutTransition());
30
         pushInitialScreen(initialScreenParams);
32
         pushInitialScreen(initialScreenParams);
31
     }
33
     }
41
     }
43
     }
42
 
44
 
43
     private void addScreen(ScreenParams screenParams) {
45
     private void addScreen(ScreenParams screenParams) {
44
-        Screen screen = ScreenFactory.create(activity, screenParams, this);
46
+        Screen screen = ScreenFactory.create(activity, screenParams, titleBarBackButtonListener);
45
         addView(screen, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
47
         addView(screen, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
46
         stack.push(screen);
48
         stack.push(screen);
47
     }
49
     }
131
         performOnScreen(screenInstanceId, new Task<Screen>() {
133
         performOnScreen(screenInstanceId, new Task<Screen>() {
132
             @Override
134
             @Override
133
             public void run(Screen param) {
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
     public StyleParams getCurrentScreenStyleParams() {
141
     public StyleParams getCurrentScreenStyleParams() {
147
         return stack.peek().getStyleParams();
142
         return stack.peek().getStyleParams();
148
     }
143
     }