Skip to content

Commit

Permalink
Fix crash when updating dialog props after the Activity has disappeared
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jun 29, 2020
1 parent fb2b49d commit 7abcaaf
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -347,24 +348,26 @@ private void updateProperties() {
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);
}
}

Expand Down

0 comments on commit 7abcaaf

Please sign in to comment.