Kaynağa Gözat

Navigator searches for controllers in OverlayManager as well

Fixes #4225
Guy Carmeli 6 yıl önce
ebeveyn
işleme
af046eaae6

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OverlayManager.java Dosyayı Görüntüle

@@ -37,4 +37,8 @@ public class OverlayManager {
37 37
     public int size() {
38 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 Dosyayı Görüntüle

@@ -196,7 +196,13 @@ public class Navigator extends ParentController {
196 196
     @Override
197 197
     public ViewController findController(String id) {
198 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 208
     private void applyOnStack(String fromId, CommandListener listener, Task<StackController> task) {
@@ -217,7 +223,7 @@ public class Navigator extends ParentController {
217 223
     }
218 224
 
219 225
     @RestrictTo(RestrictTo.Scope.TESTS)
220
-    public FrameLayout getModalsLayout() {
226
+    FrameLayout getModalsLayout() {
221 227
         return modalsLayout;
222 228
     }
223 229
 }

+ 20
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java Dosyayı Görüntüle

@@ -71,7 +71,7 @@ public class NavigatorTest extends BaseTest {
71 71
     public void beforeEach() {
72 72
         childRegistry = new ChildControllersRegistry();
73 73
         eventEmitter = Mockito.mock(EventEmitter.class);
74
-        overlayManager = Mockito.mock(OverlayManager.class);
74
+        overlayManager = spy(new OverlayManager());
75 75
         imageLoaderMock = ImageLoaderMock.mock();
76 76
         activityController = newActivityController(TestActivity.class);
77 77
         activity = activityController.create().get();
@@ -349,6 +349,24 @@ public class NavigatorTest extends BaseTest {
349 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 370
     @NonNull
353 371
     private StackController newStack() {
354 372
         StackController stack = TestUtils.newStackController(activity)
@@ -588,7 +606,7 @@ public class NavigatorTest extends BaseTest {
588 606
     public void destroy_destroyOverlayManager() {
589 607
         uut.setRoot(parentController, new CommandListenerAdapter());
590 608
         activityController.destroy();
591
-        verify(overlayManager, times(1)).destroy();
609
+        verify(overlayManager).destroy();
592 610
     }
593 611
 
594 612
     @Test