Fix Modal not disappearing when navigating from inside a Modal to another activity
Reviewed By: achen1 Differential Revision: D6668368 fbshipit-source-id: 809e9c978032e731478bcc8e290eb030e4ee6eca
This commit is contained in:
Родитель
d85da86dc7
Коммит
e5c2a66897
|
@ -128,7 +128,10 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||||
|
|
||||||
private void dismiss() {
|
private void dismiss() {
|
||||||
if (mDialog != null) {
|
if (mDialog != null) {
|
||||||
mDialog.dismiss();
|
Activity currentActivity = getCurrentActivity();
|
||||||
|
if (mDialog.isShowing() && (currentActivity == null || !currentActivity.isFinishing())) {
|
||||||
|
mDialog.dismiss();
|
||||||
|
}
|
||||||
mDialog = null;
|
mDialog = null;
|
||||||
|
|
||||||
// We need to remove the mHostView from the parent
|
// We need to remove the mHostView from the parent
|
||||||
|
@ -168,8 +171,7 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHostPause() {
|
public void onHostPause() {
|
||||||
// We dismiss the dialog and reconstitute it onHostResume
|
// do nothing
|
||||||
dismiss();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,6 +185,10 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||||
return mDialog;
|
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
|
* 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
|
* because we need to know all of them before creating the Dialog. It is also smart during
|
||||||
|
@ -209,7 +215,9 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||||
} else if (mAnimationType.equals("slide")) {
|
} else if (mAnimationType.equals("slide")) {
|
||||||
theme = R.style.Theme_FullScreenDialogAnimatedSlide;
|
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());
|
mDialog.setContentView(getContentView());
|
||||||
updateProperties();
|
updateProperties();
|
||||||
|
@ -247,7 +255,9 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||||
if (mHardwareAccelerated) {
|
if (mHardwareAccelerated) {
|
||||||
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||||
}
|
}
|
||||||
mDialog.show();
|
if (currentActivity == null || !currentActivity.isFinishing()) {
|
||||||
|
mDialog.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Загрузка…
Ссылка в новой задаче