Skip to content

Commit

Permalink
Fix Modal not disappearing when navigating from inside a Modal to ano…
Browse files Browse the repository at this point in the history
…ther activity

Reviewed By: achen1

Differential Revision: D6668368

fbshipit-source-id: 809e9c978032e731478bcc8e290eb030e4ee6eca
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 8, 2018
1 parent d85da86 commit e5c2a66
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ public void onDropInstance() {

private void dismiss() {
if (mDialog != null) {
mDialog.dismiss();
Activity currentActivity = getCurrentActivity();
if (mDialog.isShowing() && (currentActivity == null || !currentActivity.isFinishing())) {
mDialog.dismiss();
}
mDialog = null;

// We need to remove the mHostView from the parent
Expand Down Expand Up @@ -168,8 +171,7 @@ public void onHostResume() {

@Override
public void onHostPause() {
// We dismiss the dialog and reconstitute it onHostResume
dismiss();
// do nothing
}

@Override
Expand All @@ -183,6 +185,10 @@ public void onHostDestroy() {
return mDialog;
}

private @Nullable Activity getCurrentActivity() {
return ((ReactContext) getContext()).getCurrentActivity();
}

/**
* showOrUpdate will display the Dialog. It is called by the manager once all properties are set
* because we need to know all of them before creating the Dialog. It is also smart during
Expand All @@ -209,7 +215,9 @@ protected void showOrUpdate() {
} else if (mAnimationType.equals("slide")) {
theme = R.style.Theme_FullScreenDialogAnimatedSlide;
}
mDialog = new Dialog(getContext(), theme);
Activity currentActivity = getCurrentActivity();
Context context = currentActivity == null ? getContext() : currentActivity;
mDialog = new Dialog(context, theme);

mDialog.setContentView(getContentView());
updateProperties();
Expand Down Expand Up @@ -247,7 +255,9 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (mHardwareAccelerated) {
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}
mDialog.show();
if (currentActivity == null || !currentActivity.isFinishing()) {
mDialog.show();
}
}

/**
Expand Down

0 comments on commit e5c2a66

Please sign in to comment.