Browse Source

Navigator searches for controllers in OverlayManager as well

Fixes #4225
Guy Carmeli 6 years ago
parent
commit
af046eaae6

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OverlayManager.java View File

37
     public int size() {
37
     public int size() {
38
         return overlayRegistry.size();
38
         return overlayRegistry.size();
39
     }
39
     }
40
+
41
+    public ViewController findControllerById(String id) {
42
+        return overlayRegistry.get(id);
43
+    }
40
 }
44
 }

+ 8
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/navigator/Navigator.java View File

196
     @Override
196
     @Override
197
     public ViewController findController(String id) {
197
     public ViewController findController(String id) {
198
         ViewController controllerById = super.findController(id);
198
         ViewController controllerById = super.findController(id);
199
-        return controllerById != null ? controllerById : modalStack.findControllerById(id);
199
+        if (controllerById == null) {
200
+            controllerById = modalStack.findControllerById(id);
201
+        }
202
+        if (controllerById == null) {
203
+            controllerById = overlayManager.findControllerById(id);
204
+        }
205
+        return controllerById;
200
     }
206
     }
201
 
207
 
202
     private void applyOnStack(String fromId, CommandListener listener, Task<StackController> task) {
208
     private void applyOnStack(String fromId, CommandListener listener, Task<StackController> task) {
217
     }
223
     }
218
 
224
 
219
     @RestrictTo(RestrictTo.Scope.TESTS)
225
     @RestrictTo(RestrictTo.Scope.TESTS)
220
-    public FrameLayout getModalsLayout() {
226
+    FrameLayout getModalsLayout() {
221
         return modalsLayout;
227
         return modalsLayout;
222
     }
228
     }
223
 }
229
 }

+ 20
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java View File

71
     public void beforeEach() {
71
     public void beforeEach() {
72
         childRegistry = new ChildControllersRegistry();
72
         childRegistry = new ChildControllersRegistry();
73
         eventEmitter = Mockito.mock(EventEmitter.class);
73
         eventEmitter = Mockito.mock(EventEmitter.class);
74
-        overlayManager = Mockito.mock(OverlayManager.class);
74
+        overlayManager = spy(new OverlayManager());
75
         imageLoaderMock = ImageLoaderMock.mock();
75
         imageLoaderMock = ImageLoaderMock.mock();
76
         activityController = newActivityController(TestActivity.class);
76
         activityController = newActivityController(TestActivity.class);
77
         activity = activityController.create().get();
77
         activity = activityController.create().get();
349
         return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options(), new Presenter(activity, new Options()), new BottomTabsPresenter(tabs, new Options()), new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options()));
349
         return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options(), new Presenter(activity, new Options()), new BottomTabsPresenter(tabs, new Options()), new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options()));
350
     }
350
     }
351
 
351
 
352
+    @Test
353
+    public void findController_root() {
354
+        uut.setRoot(child1, new CommandListenerAdapter());
355
+        assertThat(uut.findController(child1.getId())).isEqualTo(child1);
356
+    }
357
+
358
+    @Test
359
+    public void findController_overlay() {
360
+        uut.showOverlay(child1, new CommandListenerAdapter());
361
+        assertThat(uut.findController(child1.getId())).isEqualTo(child1);
362
+    }
363
+
364
+    @Test
365
+    public void findController_modal() {
366
+        uut.showModal(child1, new CommandListenerAdapter());
367
+        assertThat(uut.findController(child1.getId())).isEqualTo(child1);
368
+    }
369
+
352
     @NonNull
370
     @NonNull
353
     private StackController newStack() {
371
     private StackController newStack() {
354
         StackController stack = TestUtils.newStackController(activity)
372
         StackController stack = TestUtils.newStackController(activity)
588
     public void destroy_destroyOverlayManager() {
606
     public void destroy_destroyOverlayManager() {
589
         uut.setRoot(parentController, new CommandListenerAdapter());
607
         uut.setRoot(parentController, new CommandListenerAdapter());
590
         activityController.destroy();
608
         activityController.destroy();
591
-        verify(overlayManager, times(1)).destroy();
609
+        verify(overlayManager).destroy();
592
     }
610
     }
593
 
611
 
594
     @Test
612
     @Test