Bladeren bron

Fix popToRoot when keyboard is visible (#655)

* Fix bug in popToRoot when keyboard is visible

* Add comments

* code review changes

* Add final to function parameters
Varun Gupta 8 jaren geleden
bovenliggende
commit
e4f575f15c

+ 8
- 4
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java Bestand weergeven

@@ -266,16 +266,20 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
266 266
             @Override
267 267
             public void onScreenPopAnimationEnd() {
268 268
                 setBottomTabsStyleFromCurrentScreen();
269
+                EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
269 270
             }
270 271
         });
271
-        EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
272 272
     }
273 273
 
274 274
     @Override
275 275
     public void popToRoot(ScreenParams params) {
276
-        getCurrentScreenStack().popToRoot(params.animateScreenTransitions);
277
-        setBottomTabsStyleFromCurrentScreen();
278
-        EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
276
+        getCurrentScreenStack().popToRoot(params.animateScreenTransitions, new ScreenStack.OnScreenPop() {
277
+            @Override
278
+            public void onScreenPopAnimationEnd() {
279
+                setBottomTabsStyleFromCurrentScreen();
280
+                EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
281
+            }
282
+        });
279 283
     }
280 284
 
281 285
     @Override

+ 12
- 4
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Bestand weergeven

@@ -135,14 +135,22 @@ public class SingleScreenLayout extends BaseLayout {
135 135
 
136 136
     @Override
137 137
     public void pop(ScreenParams params) {
138
-        stack.pop(params.animateScreenTransitions);
139
-        EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
138
+        stack.pop(params.animateScreenTransitions, new ScreenStack.OnScreenPop() {
139
+            @Override
140
+            public void onScreenPopAnimationEnd() {
141
+                EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
142
+            }
143
+        });
140 144
     }
141 145
 
142 146
     @Override
143 147
     public void popToRoot(ScreenParams params) {
144
-        stack.popToRoot(params.animateScreenTransitions);
145
-        EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
148
+        stack.popToRoot(params.animateScreenTransitions, new ScreenStack.OnScreenPop() {
149
+            @Override
150
+            public void onScreenPopAnimationEnd() {
151
+                EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
152
+            }
153
+        });
146 154
     }
147 155
 
148 156
     @Override

+ 29
- 7
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java Bestand weergeven

@@ -121,23 +121,26 @@ public class ScreenStack {
121 121
             return;
122 122
         }
123 123
 
124
-        final Screen toRemove = stack.pop();
125
-        final Screen previous = stack.peek();
126
-
127 124
         if (keyboardVisibilityDetector.isKeyboardVisible()) {
128 125
             keyboardVisibilityDetector.setKeyboardCloseListener(new Runnable() {
129 126
                 @Override
130 127
                 public void run() {
131 128
                     keyboardVisibilityDetector.setKeyboardCloseListener(null);
132
-                    swapScreens(animated, toRemove, previous, onScreenPop);
129
+                    popInternal(animated, onScreenPop);
133 130
                 }
134 131
             });
135 132
             keyboardVisibilityDetector.closeKeyboard();
136 133
         } else {
137
-            swapScreens(animated, toRemove, previous, onScreenPop);
134
+            popInternal(animated, onScreenPop);
138 135
         }
139 136
     }
140 137
 
138
+    private void popInternal(final boolean animated, @Nullable final OnScreenPop onScreenPop) {
139
+        final Screen toRemove = stack.pop();
140
+        final Screen previous = stack.peek();
141
+        swapScreens(animated, toRemove, previous, onScreenPop);
142
+    }
143
+
141 144
     private void swapScreens(boolean animated, final Screen toRemove, Screen previous, OnScreenPop onScreenPop) {
142 145
         readdPrevious(previous);
143 146
         previous.setStyle();
@@ -163,9 +166,28 @@ public class ScreenStack {
163 166
         parent.addView(previous, 0);
164 167
     }
165 168
 
166
-    public void popToRoot(boolean animated) {
169
+    public void popToRoot(final boolean animated, @Nullable final OnScreenPop onScreenPop) {
170
+        if (keyboardVisibilityDetector.isKeyboardVisible()) {
171
+            keyboardVisibilityDetector.setKeyboardCloseListener(new Runnable() {
172
+                @Override
173
+                public void run() {
174
+                    keyboardVisibilityDetector.setKeyboardCloseListener(null);
175
+                    popToRootInternal(animated, onScreenPop);
176
+                }
177
+            });
178
+            keyboardVisibilityDetector.closeKeyboard();
179
+        } else {
180
+            popToRootInternal(animated, onScreenPop);
181
+        }
182
+    }
183
+
184
+    private void popToRootInternal(final boolean animated, @Nullable final OnScreenPop onScreenPop) {
167 185
         while (canPop()) {
168
-            pop(animated);
186
+            if (stack.size() == 2) {
187
+                popInternal(animated, onScreenPop);
188
+            } else {
189
+                popInternal(animated, null);
190
+            }
169 191
         }
170 192
     }
171 193