Skip to content

Commit

Permalink
Fix crash when calling setStackRoot multiple times in quick succession (
Browse files Browse the repository at this point in the history
#4843)

Previous push animation wasn’t cancelled, when it ended the controller tried
to destroy previous view which was already destroyed.
  • Loading branch information
guyca authored Mar 10, 2019
1 parent 47b7d2c commit fdee254
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ private void addChildToStack(ViewController child, View view, Options resolvedOp
}

public void setRoot(List<ViewController> children, CommandListener listener) {
animator.cancelPushAnimations();
if (children.size() == 1) {
backButtonHelper.clear(CollectionUtils.last(children));
push(CollectionUtils.last(children), new CommandListenerAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fdee254

Please sign in to comment.