Skip to content

Commit

Permalink
Fix BadTokenException and IllegalArgmentException thrown when showing…
Browse files Browse the repository at this point in the history
… or dismissing Modal

Reviewed By: achen1

Differential Revision: D6531148

fbshipit-source-id: 1d3f6e041ac68ad13120c56ea5223557fca34f0d
  • Loading branch information
mdvacca authored and wilimitis committed Jan 9, 2018
1 parent 5f3f3d4 commit 37e813e
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 @@ -209,8 +212,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 All @@ -233,7 +237,7 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
} else {
// We redirect the rest of the key events to the current activity, since the activity
// expects to receive those events and react to them, ie. in the case of the dev menu
Activity currentActivity = ((ReactContext) getContext()).getCurrentActivity();
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
return currentActivity.onKeyUp(keyCode, event);
}
Expand All @@ -247,7 +251,13 @@ 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();
}
}

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

/**
Expand Down

0 comments on commit 37e813e

Please sign in to comment.