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
     }
192
     }
193
 
193
 
194
     public void setRoot(List<ViewController> children, CommandListener listener) {
194
     public void setRoot(List<ViewController> children, CommandListener listener) {
195
+        animator.cancelPushAnimations();
195
         if (children.size() == 1) {
196
         if (children.size() == 1) {
196
             backButtonHelper.clear(CollectionUtils.last(children));
197
             backButtonHelper.clear(CollectionUtils.last(children));
197
             push(CollectionUtils.last(children), new CommandListenerAdapter() {
198
             push(CollectionUtils.last(children), new CommandListenerAdapter() {

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

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
     @Test
297
     @Test
285
     public synchronized void pop() {
298
     public synchronized void pop() {
286
         disablePushAnimation(child1, child2);
299
         disablePushAnimation(child1, child2);