From a0562c7ccffea7d001499ce8e431ede5249cab5e Mon Sep 17 00:00:00 2001 From: Dave Miller Date: Thu, 26 May 2016 20:12:58 -0700 Subject: [PATCH] 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 --- .../views/modal/ReactModalHostManager.java | 2 +- .../react/views/modal/ReactModalHostView.java | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java index 4af221dd496..2fb42c594f6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java @@ -62,7 +62,7 @@ public class ReactModalHostManager extends ViewGroupManager @Override public void onDropViewInstance(ReactModalHostView view) { super.onDropViewInstance(view); - view.dismiss(); + view.onDropInstance(); } @ReactProp(name = "animationType") diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java index 24b33892a36..48b66db9f97 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java @@ -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