diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java index 1473d402311..d33fe34d404 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java @@ -192,6 +192,7 @@ private void addChildToStack(ViewController child, View view, Options resolvedOp } public void setRoot(List children, CommandListener listener) { + animator.cancelPushAnimations(); if (children.size() == 1) { backButtonHelper.clear(CollectionUtils.last(children)); push(CollectionUtils.last(children), new CommandListenerAdapter() { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java index c97349a800f..b5742b70a78 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java @@ -281,6 +281,19 @@ public void onSuccess(String childId) { }); } + @Test + public void setRoot_doesNotCrashWhenCalledInQuickSuccession() { + disablePushAnimation(child1); + uut.setRoot(Collections.singletonList(child1), new CommandListenerAdapter()); + + uut.setRoot(Collections.singletonList(child2), new CommandListenerAdapter()); + uut.setRoot(Collections.singletonList(child3), new CommandListenerAdapter()); + animator.endPushAnimation(child2.getView()); + animator.endPushAnimation(child3.getView()); + + assertContainsOnlyId(child3.getId()); + } + @Test public synchronized void pop() { disablePushAnimation(child1, child2);