Browse Source

Fix popToRoot

listener was invoked twice
Guy Carmeli 6 years ago
parent
commit
bdd4b1ebdd

+ 13
- 6
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

@@ -212,14 +212,21 @@ public class StackController extends ParentController<StackLayout> {
212 212
     }
213 213
 
214 214
     void popToRoot(CommandListener listener) {
215
-        while (canPop()) {
216
-            boolean animate = stack.size() == 2; // First element is root
217
-            if (animate) {
218
-                animatePop(listener);
219
-            } else {
220
-                pop(listener);
215
+        if (!canPop()) {
216
+            listener.onError("Nothing to pop");
217
+            return;
218
+        }
219
+
220
+        Iterator<String> iterator = stack.iterator();
221
+        while (stack.size() > 2) {
222
+            ViewController controller = stack.get(iterator.next());
223
+            if (!stack.isTop(controller.getId())) {
224
+                stack.remove(controller.getId());
225
+                controller.destroy();
221 226
             }
222 227
         }
228
+
229
+        animatePop(listener);
223 230
     }
224 231
 
225 232
     ViewController peek() {