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

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

53
 import static org.mockito.Mockito.spy;
53
 import static org.mockito.Mockito.spy;
54
 import static org.mockito.Mockito.times;
54
 import static org.mockito.Mockito.times;
55
 import static org.mockito.Mockito.verify;
55
 import static org.mockito.Mockito.verify;
56
+import static org.mockito.Mockito.verifyZeroInteractions;
56
 import static org.mockito.Mockito.when;
57
 import static org.mockito.Mockito.when;
57
 
58
 
58
 @Config(qualifiers = "xxhdpi")
59
 @Config(qualifiers = "xxhdpi")
167
         assertIsChild(uut.getRootLayout(), child2.getView());
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
     @Test
185
     @Test
171
     public void setRoot_destroysModals() {
186
     public void setRoot_destroysModals() {
172
         uut.showModal(child1, new CommandListenerAdapter());
187
         uut.showModal(child1, new CommandListenerAdapter());