Browse Source

Fix crash when calling setStackRoot multiple times in quick succession (#4843)

Previous push animation wasn’t cancelled, when it ended the controller tried
to destroy previous view which was already destroyed.
Guy Carmeli 5 years ago
parent
commit
fdee25422f
No account linked to committer's email address

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java View File

@@ -192,6 +192,7 @@ public class StackController extends ParentController<StackLayout> {
192 192
     }
193 193
 
194 194
     public void setRoot(List<ViewController> children, CommandListener listener) {
195
+        animator.cancelPushAnimations();
195 196
         if (children.size() == 1) {
196 197
             backButtonHelper.clear(CollectionUtils.last(children));
197 198
             push(CollectionUtils.last(children), new CommandListenerAdapter() {

+ 13
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java View File

@@ -281,6 +281,19 @@ public class StackControllerTest extends BaseTest {
281 281
         });
282 282
     }
283 283
 
284
+    @Test
285
+    public void setRoot_doesNotCrashWhenCalledInQuickSuccession() {
286
+        disablePushAnimation(child1);
287
+        uut.setRoot(Collections.singletonList(child1), new CommandListenerAdapter());
288
+
289
+        uut.setRoot(Collections.singletonList(child2), new CommandListenerAdapter());
290
+        uut.setRoot(Collections.singletonList(child3), new CommandListenerAdapter());
291
+        animator.endPushAnimation(child2.getView());
292
+        animator.endPushAnimation(child3.getView());
293
+
294
+        assertContainsOnlyId(child3.getId());
295
+    }
296
+
284 297
     @Test
285 298
     public synchronized void pop() {
286 299
         disablePushAnimation(child1, child2);