Kaynağa Gözat

Fix crash when reloading when a modal was displayed

Guy Carmeli 6 yıl önce
ebeveyn
işleme
7723e4df70

+ 12
- 3
lib/android/app/src/main/java/com/reactnativenavigation/react/ReactView.java Dosyayı Görüntüle

60
 
60
 
61
 	@Override
61
 	@Override
62
 	public void sendComponentStart() {
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
 	@Override
69
 	@Override
67
 	public void sendComponentStop() {
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
     @Override
77
     @Override
72
 	public void sendOnNavigationButtonPressed(String buttonId) {
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
     @Override
85
     @Override

+ 3
- 4
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Dosyayı Görüntüle

17
 import com.reactnativenavigation.utils.CommandListener;
17
 import com.reactnativenavigation.utils.CommandListener;
18
 import com.reactnativenavigation.utils.CommandListenerAdapter;
18
 import com.reactnativenavigation.utils.CommandListenerAdapter;
19
 import com.reactnativenavigation.utils.CompatUtils;
19
 import com.reactnativenavigation.utils.CompatUtils;
20
-import com.reactnativenavigation.utils.NativeCommandListener;
21
 import com.reactnativenavigation.viewcontrollers.modal.ModalPresenter;
20
 import com.reactnativenavigation.viewcontrollers.modal.ModalPresenter;
22
 import com.reactnativenavigation.viewcontrollers.modal.ModalStack;
21
 import com.reactnativenavigation.viewcontrollers.modal.ModalStack;
23
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
22
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
86
     }
85
     }
87
 
86
 
88
     private void destroyViews() {
87
     private void destroyViews() {
89
-        destroyRoot();
90
-        overlayManager.destroy();
91
         modalStack.dismissAllModals(new CommandListenerAdapter(), root);
88
         modalStack.dismissAllModals(new CommandListenerAdapter(), root);
89
+        overlayManager.destroy();
90
+        destroyRoot();
92
     }
91
     }
93
 
92
 
94
     private void destroyRoot() {
93
     private void destroyRoot() {
189
         modalStack.dismissAllModals(listener, root);
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
         overlayManager.show(rootLayout, overlay, listener);
192
         overlayManager.show(rootLayout, overlay, listener);
194
     }
193
     }
195
 
194
 

+ 10
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Dosyayı Görüntüle

464
         verify(overlayManager, times(1)).destroy();
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
     @Test
477
     @Test
468
     public void reload_navigatorIsDestroyedOnReload() {
478
     public void reload_navigatorIsDestroyedOnReload() {
469
         uut.setRoot(parentController, new CommandListenerAdapter());
479
         uut.setRoot(parentController, new CommandListenerAdapter());