Sfoglia il codice sorgente

[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 anni fa
parent
commit
ebbb829d8c

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

@@ -129,4 +129,8 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
129 129
         view.setBackgroundColor(Color.WHITE);
130 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 Vedi File

@@ -179,4 +179,13 @@ public class NavigationModule extends ReactContextBaseJavaModule {
179 179
     private NavigationActivity activity() {
180 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
 }