Browse Source

Add previous screen at index 0 when popping

Guy Carmeli 6 years ago
parent
commit
db567ea7b3

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

@@ -105,6 +105,8 @@ public class StackController extends ParentController<StackLayout> {
105 105
                 getView().removeView(toRemove.getView());
106 106
                 listener.onSuccess(child.getId());
107 107
             }
108
+        } else {
109
+            listener.onSuccess(child.getId());
108 110
         }
109 111
     }
110 112
 
@@ -138,9 +140,7 @@ public class StackController extends ParentController<StackLayout> {
138 140
         final ViewController appearing = stack.peek();
139 141
         disappearing.onViewWillDisappear();
140 142
         appearing.onViewWillAppear();
141
-        getView().onChildWillDisappear(disappearing.options, appearing.options, () ->
142
-                getView().addView(appearing.getView())
143
-        );
143
+        getView().onChildWillDisappear(disappearing.options, appearing.options, () -> getView().addView(appearing.getView(), 0));
144 144
 
145 145
         if (disappearing.options.animated.isTrueOrUndefined()) {
146 146
             animator.pop(disappearing.getView(), () -> finishPopping(disappearing, listener));

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

@@ -76,8 +76,10 @@ public class StackControllerTest extends BaseTest {
76 76
     @Test
77 77
     public void push() {
78 78
         assertThat(uut.isEmpty()).isTrue();
79
-        uut.push(child1, new CommandListenerAdapter());
79
+        CommandListenerAdapter listener = spy(new CommandListenerAdapter());
80
+        uut.push(child1, listener);
80 81
         assertContainsOnlyId(child1.getId());
82
+        verify(listener, times(1)).onSuccess(child1.getId());
81 83
     }
82 84
 
83 85
     @Test
@@ -202,7 +204,7 @@ public class StackControllerTest extends BaseTest {
202 204
     }
203 205
 
204 206
     @Test
205
-    public void popDoesNothingWhenZeroOrOneChild() {
207
+    public void pop_doesNothingWhenZeroOrOneChild() {
206 208
         assertThat(uut.isEmpty()).isTrue();
207 209
         uut.pop(new CommandListenerAdapter());
208 210
         assertThat(uut.isEmpty()).isTrue();