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
         if (isShown) {
189
         if (isShown) {
190
             isShown = false;
190
             isShown = false;
191
             onViewDisappear();
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
         if (view != null) {
196
         if (view != null) {
197
             view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
197
             view.getViewTreeObserver().removeOnGlobalLayoutListener(this);

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

189
         verify(spy, times(1)).onViewDisappear();
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
     @Test
208
     @Test
193
     public void onDestroy_RemovesSelfFromParentIfExists() {
209
     public void onDestroy_RemovesSelfFromParentIfExists() {
194
         LinearLayout parent = new LinearLayout(activity);
210
         LinearLayout parent = new LinearLayout(activity);