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

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

@@ -361,7 +361,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
361 361
         if (event.getType().equals(ModalDismissedEvent.TYPE)) {
362 362
             handleModalDismissedEvent();
363 363
         } else if (event.getType().equals(JsDevReloadEvent.TYPE)) {
364
-            handleJsDevReloadEvent();
364
+            postHandleJsDevReloadEvent();
365 365
         }
366 366
     }
367 367
 
@@ -375,9 +375,14 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
375 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 388
     @TargetApi(Build.VERSION_CODES.M)

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

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