Fix Modal when the Activity is paused or resumed
Summary: When the activity hosting a Modal goes away, we should dismiss the dialog from the stack and then reconstitute it when the activity comes back. This means that if an activity is paused because another activity is placed on top of it but our ui operation was delayed, it will not blow up finding no window since it is gone. Also fixes a place where we should remove a listener for lifecycle events which we were not doing. Reviewed By: halfjuice Differential Revision: D3357286 fbshipit-source-id: c5c6dd8e5ef299762ed9aa15a6910ce9c0b111dc
This commit is contained in:
parent
f7279b4074
commit
a0562c7ccf
|
@ -62,7 +62,7 @@ public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView>
|
|||
@Override
|
||||
public void onDropViewInstance(ReactModalHostView view) {
|
||||
super.onDropViewInstance(view);
|
||||
view.dismiss();
|
||||
view.onDropInstance();
|
||||
}
|
||||
|
||||
@ReactProp(name = "animationType")
|
||||
|
|
|
@ -109,7 +109,12 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
|||
// Those will be handled by the mHostView which lives in the dialog
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
public void onDropInstance() {
|
||||
((ReactContext) getContext()).removeLifecycleEventListener(this);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void dismiss() {
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog = null;
|
||||
|
@ -140,18 +145,20 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
|||
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
// do nothing
|
||||
// We show the dialog again when the host resumes
|
||||
showOrUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostPause() {
|
||||
// do nothing
|
||||
// We dismiss the dialog and reconstitute it onHostResume
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostDestroy() {
|
||||
// Dismiss the dialog if it is present
|
||||
dismiss();
|
||||
// Drop the instance if the host is destroyed which will dismiss the dialog
|
||||
onDropInstance();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
Loading…
Reference in New Issue