Browse Source

Reject is pushing to a layout which is not contained in a stack

Guy Carmeli 6 years ago
parent
commit
b9b627122a

+ 13
- 6
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

@@ -129,13 +129,12 @@ public class Navigator extends ParentController {
129 129
     public void push(final String fromId, final ViewController viewController, CommandListener listener) {
130 130
         ViewController from = findControllerById(fromId);
131 131
         if (from != null) {
132
-            from.performOnParentStack(stack -> ((StackController) stack).push(viewController, listener));
132
+            from.performOnParentStack(
133
+                    stack -> ((StackController) stack).push(viewController, listener),
134
+                    () -> rejectPush(fromId, viewController, listener)
135
+            );
133 136
         } else {
134
-            listener.onError("Could not push component: " +
135
-                             viewController.getId() +
136
-                             ". Stack with id " +
137
-                             fromId +
138
-                             " was not found.");
137
+            rejectPush(fromId, viewController, listener);
139 138
         }
140 139
     }
141 140
 
@@ -204,4 +203,12 @@ public class Navigator extends ParentController {
204 203
         ViewController controllerById = super.findControllerById(id);
205 204
         return controllerById != null ? controllerById : modalStack.findControllerById(id);
206 205
     }
206
+
207
+    private void rejectPush(String fromId, ViewController viewController, CommandListener listener) {
208
+        listener.onError("Could not push component: " +
209
+                         viewController.getId() +
210
+                         ". Stack with id " +
211
+                         fromId +
212
+                         " was not found.");
213
+    }
207 214
 }

+ 7
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

@@ -83,7 +83,6 @@ public class NavigatorTest extends BaseTest {
83 83
             }
84 84
         });
85 85
         parentController.setViewVisibilityListener(parentVisibilityListener);
86
-//        parentController.ensureViewIsCreated();
87 86
         child1 = new SimpleViewController(activity, childRegistry, "child1", tabOptions);
88 87
         child2 = new SimpleViewController(activity, childRegistry, "child2", tabOptions);
89 88
         child3 = new SimpleViewController(activity, childRegistry, "child3", tabOptions);
@@ -164,6 +163,13 @@ public class NavigatorTest extends BaseTest {
164 163
         assertThat(stack2.getChildControllers()).contains(newChild);
165 164
     }
166 165
 
166
+    @Test
167
+    public void push_rejectIfNotContainedInStack() {
168
+        CommandListener listener = Mockito.mock(CommandListener.class);
169
+        uut.push("someId", child1, listener);
170
+        verify(listener).onError(any());
171
+    }
172
+
167 173
     @Test
168 174
     public void pop_InvalidDoesNothing() {
169 175
         uut.pop("123", new CommandListenerAdapter());