Skip to content

Commit 7abcaaf

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Fix crash when updating dialog props after the Activity has disappeared
Summary: This diff avoids accessing window and activities object that has dissapear changelog: [Android][Fix] Fix crash when updating RN dialog props after the activity disappeared Reviewed By: JoshuaGross Differential Revision: D22264672 fbshipit-source-id: 89c9895c8c6b6fec383a0e160847e5059616e265
1 parent fb2b49d commit 7abcaaf

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java

+17-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.view.View;
1818
import android.view.ViewGroup;
1919
import android.view.ViewStructure;
20+
import android.view.Window;
2021
import android.view.WindowManager;
2122
import android.view.accessibility.AccessibilityEvent;
2223
import android.widget.FrameLayout;
@@ -347,24 +348,26 @@ private void updateProperties() {
347348
Assertions.assertNotNull(mDialog, "mDialog must exist when we call updateProperties");
348349

349350
Activity currentActivity = getCurrentActivity();
350-
if (currentActivity != null) {
351-
int activityWindowFlags = currentActivity.getWindow().getAttributes().flags;
352-
if ((activityWindowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
353-
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
354-
} else {
355-
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
356-
}
351+
352+
Window window = mDialog.getWindow();
353+
if (currentActivity == null || currentActivity.isFinishing() || !window.isActive()) {
354+
// If the activity has disappeared, then we shouldn't update the window associated to the
355+
// Dialog.
356+
return;
357+
}
358+
int activityWindowFlags = currentActivity.getWindow().getAttributes().flags;
359+
if ((activityWindowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
360+
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
361+
} else {
362+
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
357363
}
358364

359365
if (mTransparent) {
360-
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
366+
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
361367
} else {
362-
mDialog.getWindow().setDimAmount(0.5f);
363-
mDialog
364-
.getWindow()
365-
.setFlags(
366-
WindowManager.LayoutParams.FLAG_DIM_BEHIND,
367-
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
368+
window.setDimAmount(0.5f);
369+
window.setFlags(
370+
WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);
368371
}
369372
}
370373

0 commit comments

Comments
 (0)