Browse Source

Unmount ReactRootView even if it's hidden

There was an issue where ReactRootView was not unmounted if it was destroyed when it was hidden.
Guy Carmeli 6 years ago
parent
commit
934cde7495

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java View File

@@ -189,9 +189,9 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
189 189
         if (isShown) {
190 190
             isShown = false;
191 191
             onViewDisappear();
192
-            if (view instanceof Destroyable) {
193
-                ((Destroyable) view).destroy();
194
-            }
192
+        }
193
+        if (view instanceof Destroyable) {
194
+            ((Destroyable) view).destroy();
195 195
         }
196 196
         if (view != null) {
197 197
             view.getViewTreeObserver().removeOnGlobalLayoutListener(this);

+ 16
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java View File

@@ -189,6 +189,22 @@ public class ViewControllerTest extends BaseTest {
189 189
         verify(spy, times(1)).onViewDisappear();
190 190
     }
191 191
 
192
+    @Test
193
+    public void onDestroy_destroysViewEvenIfHidden() {
194
+        final SimpleViewController.SimpleView[] spy = new SimpleViewController.SimpleView[1];
195
+        ViewController uut = new SimpleViewController(activity, childRegistry, "uut", new Options()) {
196
+            @Override
197
+            protected SimpleView createView() {
198
+                SimpleView view = spy(super.createView());
199
+                spy[0] = view;
200
+                return view;
201
+            }
202
+        };
203
+        assertThat(uut.isViewShown()).isFalse();
204
+        uut.destroy();
205
+        verify(spy[0], times(1)).destroy();
206
+    }
207
+
192 208
     @Test
193 209
     public void onDestroy_RemovesSelfFromParentIfExists() {
194 210
         LinearLayout parent = new LinearLayout(activity);