Browse Source

Minor fixes to reload flow (#1103)

This is mostly a workaround to overcome faults in the simple event bus implementation,
also fixes crash when reloading while modal is displayed.
Guy Carmeli 7 years ago
parent
commit
57b745ca95

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java View File

29
     private final OnModalDismissedListener onModalDismissedListener;
29
     private final OnModalDismissedListener onModalDismissedListener;
30
     private final ScreenParams screenParams;
30
     private final ScreenParams screenParams;
31
     private Layout layout;
31
     private Layout layout;
32
+    private boolean isDestroyed;
32
 
33
 
33
     public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
34
     public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
34
         layout.setTopBarVisible(screenInstanceId, hidden, animated);
35
         layout.setTopBarVisible(screenInstanceId, hidden, animated);
149
 
150
 
150
     @Override
151
     @Override
151
     public void destroy() {
152
     public void destroy() {
153
+        isDestroyed = true;
152
         layout.destroy();
154
         layout.destroy();
153
     }
155
     }
154
 
156
 
161
 
163
 
162
     @Override
164
     @Override
163
     public void onDismiss(DialogInterface dialog) {
165
     public void onDismiss(DialogInterface dialog) {
166
+        if (isDestroyed) {
167
+            return;
168
+        }
164
         destroy();
169
         destroy();
165
         setOrientation(AppStyle.appStyle.orientation);
170
         setOrientation(AppStyle.appStyle.orientation);
166
         onModalDismissedListener.onModalDismissed(this);
171
         onModalDismissedListener.onModalDismissed(this);

+ 9
- 4
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

361
         if (event.getType().equals(ModalDismissedEvent.TYPE)) {
361
         if (event.getType().equals(ModalDismissedEvent.TYPE)) {
362
             handleModalDismissedEvent();
362
             handleModalDismissedEvent();
363
         } else if (event.getType().equals(JsDevReloadEvent.TYPE)) {
363
         } else if (event.getType().equals(JsDevReloadEvent.TYPE)) {
364
-            handleJsDevReloadEvent();
364
+            postHandleJsDevReloadEvent();
365
         }
365
         }
366
     }
366
     }
367
 
367
 
375
         return modalController.isShowing() ? modalController.getWindow() : getWindow();
375
         return modalController.isShowing() ? modalController.getWindow() : getWindow();
376
     }
376
     }
377
 
377
 
378
-    private void handleJsDevReloadEvent() {
379
-        modalController.destroy();
380
-        layout.destroy();
378
+    private void postHandleJsDevReloadEvent() {
379
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
380
+            @Override
381
+            public void run() {
382
+                layout.destroy();
383
+                modalController.destroy();
384
+            }
385
+        });
381
     }
386
     }
382
 
387
 
383
     @TargetApi(Build.VERSION_CODES.M)
388
     @TargetApi(Build.VERSION_CODES.M)

+ 5
- 5
android/app/src/main/java/com/reactnativenavigation/react/JsDevReloadListenerReplacer.java View File

5
 import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
5
 import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
6
 import com.reactnativenavigation.utils.ReflectionUtils;
6
 import com.reactnativenavigation.utils.ReflectionUtils;
7
 
7
 
8
-public class JsDevReloadListenerReplacer {
8
+class JsDevReloadListenerReplacer {
9
     private final ReactInstanceManager reactInstanceManager;
9
     private final ReactInstanceManager reactInstanceManager;
10
     private final Listener listener;
10
     private final Listener listener;
11
 
11
 
12
-    public interface Listener {
12
+    interface Listener {
13
         void onJsDevReload();
13
         void onJsDevReload();
14
     }
14
     }
15
 
15
 
16
-    public JsDevReloadListenerReplacer(ReactInstanceManager reactInstanceManager, Listener listener) {
16
+    JsDevReloadListenerReplacer(ReactInstanceManager reactInstanceManager, Listener listener) {
17
         this.reactInstanceManager = reactInstanceManager;
17
         this.reactInstanceManager = reactInstanceManager;
18
         this.listener = listener;
18
         this.listener = listener;
19
     }
19
     }
20
 
20
 
21
-    public void replace() {
21
+    void replace() {
22
         ReactInstanceDevCommandsHandler originalHandler = getOriginalHandler();
22
         ReactInstanceDevCommandsHandler originalHandler = getOriginalHandler();
23
         DevCommandsHandlerProxy proxy = new DevCommandsHandlerProxy(originalHandler, listener);
23
         DevCommandsHandlerProxy proxy = new DevCommandsHandlerProxy(originalHandler, listener);
24
         replaceInReactInstanceManager(proxy);
24
         replaceInReactInstanceManager(proxy);
42
         private ReactInstanceDevCommandsHandler originalReactHandler;
42
         private ReactInstanceDevCommandsHandler originalReactHandler;
43
         private final Listener listener;
43
         private final Listener listener;
44
 
44
 
45
-        public DevCommandsHandlerProxy(ReactInstanceDevCommandsHandler originalReactHandler, Listener listener) {
45
+        DevCommandsHandlerProxy(ReactInstanceDevCommandsHandler originalReactHandler, Listener listener) {
46
             this.originalReactHandler = originalReactHandler;
46
             this.originalReactHandler = originalReactHandler;
47
             this.listener = listener;
47
             this.listener = listener;
48
         }
48
         }