Browse Source

Fix setRoot wait for render (#5309)

Fix white screen after calling setRoot() before rendering. Fix #5308
rverbytskyi 5 years ago
parent
commit
f39f12356d

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

@@ -33,6 +33,7 @@ public class Navigator extends ParentController {
33 33
     private final OverlayManager overlayManager;
34 34
     private final RootPresenter rootPresenter;
35 35
     private ViewController root;
36
+    private ViewController previousRoot;
36 37
     private final FrameLayout rootLayout;
37 38
     private final FrameLayout modalsLayout;
38 39
     private final FrameLayout overlaysLayout;
@@ -122,13 +123,18 @@ public class Navigator extends ParentController {
122 123
         root = null;
123 124
     }
124 125
 
126
+    private void destroyPreviousRoot() {
127
+        if (previousRoot != null) previousRoot.destroy();
128
+        previousRoot = null;
129
+    }
130
+
125 131
     @Override
126 132
     public void sendOnNavigationButtonPressed(String buttonId) {
127 133
 
128 134
     }
129 135
 
130 136
     public void setRoot(final ViewController viewController, CommandListener commandListener, ReactInstanceManager reactInstanceManager) {
131
-        destroyRoot();
137
+        previousRoot = root;
132 138
         modalStack.destroy();
133 139
         final boolean removeSplashView = isRootNotCreated();
134 140
         if (isRootNotCreated()) getView();
@@ -138,6 +144,7 @@ public class Navigator extends ParentController {
138 144
             public void onSuccess(String childId) {
139 145
                 if (removeSplashView) removePreviousContentView();
140 146
                 super.onSuccess(childId);
147
+                destroyPreviousRoot();
141 148
             }
142 149
 
143 150
             private void removePreviousContentView() {

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

@@ -53,6 +53,7 @@ import static org.mockito.ArgumentMatchers.eq;
53 53
 import static org.mockito.Mockito.spy;
54 54
 import static org.mockito.Mockito.times;
55 55
 import static org.mockito.Mockito.verify;
56
+import static org.mockito.Mockito.verifyZeroInteractions;
56 57
 import static org.mockito.Mockito.when;
57 58
 
58 59
 @Config(qualifiers = "xxhdpi")
@@ -167,6 +168,20 @@ public class NavigatorTest extends BaseTest {
167 168
         assertIsChild(uut.getRootLayout(), child2.getView());
168 169
     }
169 170
 
171
+    @Test
172
+    public void setRoot_WithWaitForRender() {
173
+        ViewController primaryView = spy(child2);
174
+        uut.setRoot(primaryView, new CommandListenerAdapter(), reactInstanceManager);
175
+        child3.options.animations.setRoot.waitForRender = new Bool(true);
176
+        ViewController secondaryView = spy(child3);
177
+        CommandListenerAdapter listener = spy(new CommandListenerAdapter());
178
+        uut.setRoot(secondaryView, listener, reactInstanceManager);
179
+        verify(secondaryView).addOnAppearedListener(any());
180
+        verifyZeroInteractions(listener);
181
+        assertThat(primaryView.isViewShown()).isEqualTo(true);
182
+        secondaryView.onViewAppeared();
183
+    }
184
+
170 185
     @Test
171 186
     public void setRoot_destroysModals() {
172 187
         uut.showModal(child1, new CommandListenerAdapter());