Browse Source

Fix crash when reloading when a modal was displayed

Guy Carmeli 6 years ago
parent
commit
7723e4df70

+ 12
- 3
lib/android/app/src/main/java/com/reactnativenavigation/react/ReactView.java View File

@@ -60,17 +60,26 @@ public class ReactView extends ReactRootView implements IReactView {
60 60
 
61 61
 	@Override
62 62
 	public void sendComponentStart() {
63
-		new EventEmitter(reactInstanceManager.getCurrentReactContext()).componentDidAppear(componentId, componentName);
63
+        ReactContext currentReactContext = reactInstanceManager.getCurrentReactContext();
64
+        if (currentReactContext != null) {
65
+            new EventEmitter(currentReactContext).componentDidAppear(componentId, componentName);
66
+        }
64 67
 	}
65 68
 
66 69
 	@Override
67 70
 	public void sendComponentStop() {
68
-		new EventEmitter(reactInstanceManager.getCurrentReactContext()).componentDidDisappear(componentId, componentName);
71
+        ReactContext currentReactContext = reactInstanceManager.getCurrentReactContext();
72
+        if (currentReactContext != null) {
73
+            new EventEmitter(currentReactContext).componentDidDisappear(componentId, componentName);
74
+        }
69 75
 	}
70 76
 
71 77
     @Override
72 78
 	public void sendOnNavigationButtonPressed(String buttonId) {
73
-		new EventEmitter(reactInstanceManager.getCurrentReactContext()).emitOnNavigationButtonPressed(componentId, buttonId);
79
+        ReactContext currentReactContext = reactInstanceManager.getCurrentReactContext();
80
+        if (currentReactContext != null) {
81
+            new EventEmitter(currentReactContext).emitOnNavigationButtonPressed(componentId, buttonId);
82
+        }
74 83
 	}
75 84
 
76 85
     @Override

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

@@ -17,7 +17,6 @@ import com.reactnativenavigation.react.JsDevReloadHandler;
17 17
 import com.reactnativenavigation.utils.CommandListener;
18 18
 import com.reactnativenavigation.utils.CommandListenerAdapter;
19 19
 import com.reactnativenavigation.utils.CompatUtils;
20
-import com.reactnativenavigation.utils.NativeCommandListener;
21 20
 import com.reactnativenavigation.viewcontrollers.modal.ModalPresenter;
22 21
 import com.reactnativenavigation.viewcontrollers.modal.ModalStack;
23 22
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
@@ -86,9 +85,9 @@ public class Navigator extends ParentController implements JsDevReloadHandler.Re
86 85
     }
87 86
 
88 87
     private void destroyViews() {
89
-        destroyRoot();
90
-        overlayManager.destroy();
91 88
         modalStack.dismissAllModals(new CommandListenerAdapter(), root);
89
+        overlayManager.destroy();
90
+        destroyRoot();
92 91
     }
93 92
 
94 93
     private void destroyRoot() {
@@ -189,7 +188,7 @@ public class Navigator extends ParentController implements JsDevReloadHandler.Re
189 188
         modalStack.dismissAllModals(listener, root);
190 189
     }
191 190
 
192
-    public void showOverlay(ViewController overlay, NativeCommandListener listener) {
191
+    public void showOverlay(ViewController overlay, CommandListener listener) {
193 192
         overlayManager.show(rootLayout, overlay, listener);
194 193
     }
195 194
 

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

@@ -464,6 +464,16 @@ public class NavigatorTest extends BaseTest {
464 464
         verify(overlayManager, times(1)).destroy();
465 465
     }
466 466
 
467
+    @Test
468
+    public void destroyViews() {
469
+        disableShowModalAnimation(child1);
470
+        uut.setRoot(parentController, new CommandListenerAdapter());
471
+        uut.showModal(child1, new CommandListenerAdapter());
472
+        uut.showOverlay(child2, new CommandListenerAdapter());
473
+        uut.destroy();
474
+        assertThat(childRegistry.size()).isZero();
475
+    }
476
+
467 477
     @Test
468 478
     public void reload_navigatorIsDestroyedOnReload() {
469 479
         uut.setRoot(parentController, new CommandListenerAdapter());