Browse Source

popTo animates top screen

Guy Carmeli 6 years ago
parent
commit
3bf5563fba

+ 4
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/IdStack.java View File

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3
+import android.support.annotation.NonNull;
4
+
3 5
 import com.reactnativenavigation.utils.StringUtils;
4 6
 
5 7
 import java.util.ArrayDeque;
@@ -68,7 +70,8 @@ public class IdStack<E> implements Iterable<String> {
68 70
 		return StringUtils.isEqual(id, peekId());
69 71
 	}
70 72
 
71
-	@Override
73
+	@NonNull
74
+    @Override
72 75
 	public Iterator<String> iterator() {
73 76
 		return deque.iterator();
74 77
 	}

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

@@ -180,15 +180,15 @@ public class StackController extends ParentController<StackLayout> {
180 180
         Iterator<String> iterator = stack.iterator();
181 181
         String currentControlId = iterator.next();
182 182
         while (!viewController.getId().equals(currentControlId)) {
183
-            String nextControlId = iterator.next();
184
-            boolean animate = nextControlId.equals(viewController.getId());
185
-            if (animate) {
186
-                pop(listener);
187
-            } else {
188
-                removeAndDestroyController(stack.get(currentControlId));
183
+            if (stack.isTop(currentControlId)) {
184
+                currentControlId = iterator.next();
185
+                continue;
189 186
             }
190
-            currentControlId = nextControlId;
187
+            removeAndDestroyController(stack.get(currentControlId));
188
+            currentControlId = iterator.next();
191 189
         }
190
+
191
+        pop(listener);
192 192
     }
193 193
 
194 194
     void popToRoot(CommandListener listener) {

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

@@ -43,6 +43,7 @@ public class StackControllerTest extends BaseTest {
43 43
     private ViewController child1;
44 44
     private ViewController child2;
45 45
     private ViewController child3;
46
+    private ViewController child4;
46 47
     private NavigationAnimator animator;
47 48
     private TopBarController topBarController;
48 49
 
@@ -54,6 +55,7 @@ public class StackControllerTest extends BaseTest {
54 55
         child1 = spy(new SimpleViewController(activity, "child1", new Options()));
55 56
         child2 = spy(new SimpleViewController(activity, "child2", new Options()));
56 57
         child3 = spy(new SimpleViewController(activity, "child3", new Options()));
58
+        child4 = spy(new SimpleViewController(activity, "child4", new Options()));
57 59
     }
58 60
 
59 61
     @Test
@@ -315,6 +317,26 @@ public class StackControllerTest extends BaseTest {
315 317
         assertThat(uut.size()).isEqualTo(2);
316 318
     }
317 319
 
320
+    @Test
321
+    public void popTo_animatesTopController() {
322
+        uut.push(child1, new CommandListenerAdapter());
323
+        uut.push(child2, new CommandListenerAdapter());
324
+        uut.push(child3, new CommandListenerAdapter());
325
+        uut.push(child4, new CommandListenerAdapter() {
326
+            @Override
327
+            public void onSuccess(String childId) {
328
+                uut.popTo(child2, new CommandListenerAdapter() {
329
+                    @Override
330
+                    public void onSuccess(String childId) {
331
+                        verify(animator, times(0)).animatePop(eq(child1.getView()), any());
332
+                        verify(animator, times(0)).animatePop(eq(child2.getView()), any());
333
+                        verify(animator, times(1)).animatePop(eq(child4.getView()), any());
334
+                    }
335
+                });
336
+            }
337
+        });
338
+    }
339
+
318 340
     @Test
319 341
     public void popToRoot_PopsEverythingAboveFirstController() {
320 342
         child1.options.animated = new Bool(false);