Browse Source

[V2][Android] destroy views on catalyst instance destroy to fix android crash (#4147)

* fix(NavigationActivity): destroy views on catalyst instance destroy

this fixes redscreen/crash when `ReactInstaceManager#recreateReactContextInBackground()` is called

* refactor(NavigationModule): catalyst destroy without try/catch
Evan Ricketts 6 years ago
parent
commit
ebbb829d8c

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java View File

129
         view.setBackgroundColor(Color.WHITE);
129
         view.setBackgroundColor(Color.WHITE);
130
         setContentView(view);
130
         setContentView(view);
131
     }
131
     }
132
+
133
+    public void onCatalystInstanceDestroy() {
134
+        runOnUiThread(() -> navigator.destroyViews());
135
+    }
132
 }
136
 }

+ 9
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

179
     private NavigationActivity activity() {
179
     private NavigationActivity activity() {
180
         return (NavigationActivity) getCurrentActivity();
180
         return (NavigationActivity) getCurrentActivity();
181
     }
181
     }
182
+
183
+    @Override
184
+    public void onCatalystInstanceDestroy() {
185
+        final NavigationActivity navigationActivity = activity();
186
+        if (navigationActivity != null) {
187
+            navigationActivity.onCatalystInstanceDestroy();
188
+        }
189
+        super.onCatalystInstanceDestroy();
190
+    }
182
 }
191
 }