mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fb2b49d298
commit
7abcaafd66
@@ -17,6 +17,7 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewStructure;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -347,24 +348,26 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||
Assertions.assertNotNull(mDialog, "mDialog must exist when we call updateProperties");
|
||||
|
||||
Activity currentActivity = getCurrentActivity();
|
||||
if (currentActivity != null) {
|
||||
int activityWindowFlags = currentActivity.getWindow().getAttributes().flags;
|
||||
if ((activityWindowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
|
||||
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
} else {
|
||||
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
Window window = mDialog.getWindow();
|
||||
if (currentActivity == null || currentActivity.isFinishing() || !window.isActive()) {
|
||||
// If the activity has disappeared, then we shouldn't update the window associated to the
|
||||
// Dialog.
|
||||
return;
|
||||
}
|
||||
int activityWindowFlags = currentActivity.getWindow().getAttributes().flags;
|
||||
if ((activityWindowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
if (mTransparent) {
|
||||
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
} else {
|
||||
mDialog.getWindow().setDimAmount(0.5f);
|
||||
mDialog
|
||||
.getWindow()
|
||||
.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_DIM_BEHIND,
|
||||
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
window.setDimAmount(0.5f);
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user