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
     public void push(final String fromId, final ViewController viewController, CommandListener listener) {
129
     public void push(final String fromId, final ViewController viewController, CommandListener listener) {
130
         ViewController from = findControllerById(fromId);
130
         ViewController from = findControllerById(fromId);
131
         if (from != null) {
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
         } else {
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
         ViewController controllerById = super.findControllerById(id);
203
         ViewController controllerById = super.findControllerById(id);
205
         return controllerById != null ? controllerById : modalStack.findControllerById(id);
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
             }
83
             }
84
         });
84
         });
85
         parentController.setViewVisibilityListener(parentVisibilityListener);
85
         parentController.setViewVisibilityListener(parentVisibilityListener);
86
-//        parentController.ensureViewIsCreated();
87
         child1 = new SimpleViewController(activity, childRegistry, "child1", tabOptions);
86
         child1 = new SimpleViewController(activity, childRegistry, "child1", tabOptions);
88
         child2 = new SimpleViewController(activity, childRegistry, "child2", tabOptions);
87
         child2 = new SimpleViewController(activity, childRegistry, "child2", tabOptions);
89
         child3 = new SimpleViewController(activity, childRegistry, "child3", tabOptions);
88
         child3 = new SimpleViewController(activity, childRegistry, "child3", tabOptions);
164
         assertThat(stack2.getChildControllers()).contains(newChild);
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
     @Test
173
     @Test
168
     public void pop_InvalidDoesNothing() {
174
     public void pop_InvalidDoesNothing() {
169
         uut.pop("123", new CommandListenerAdapter());
175
         uut.pop("123", new CommandListenerAdapter());