Skip to content

Commit a0562c7

Browse files
Dave MillerFacebook Github Bot 5
authored andcommitted
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
1 parent f7279b4 commit a0562c7

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Class<? extends LayoutShadowNode> getShadowNodeClass() {
6262
@Override
6363
public void onDropViewInstance(ReactModalHostView view) {
6464
super.onDropViewInstance(view);
65-
view.dismiss();
65+
view.onDropInstance();
6666
}
6767

6868
@ReactProp(name = "animationType")

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ public void addChildrenForAccessibility(ArrayList<View> outChildren) {
109109
// Those will be handled by the mHostView which lives in the dialog
110110
}
111111

112-
public void dismiss() {
112+
public void onDropInstance() {
113+
((ReactContext) getContext()).removeLifecycleEventListener(this);
114+
dismiss();
115+
}
116+
117+
private void dismiss() {
113118
if (mDialog != null) {
114119
mDialog.dismiss();
115120
mDialog = null;
@@ -140,18 +145,20 @@ protected void setAnimationType(String animationType) {
140145

141146
@Override
142147
public void onHostResume() {
143-
// do nothing
148+
// We show the dialog again when the host resumes
149+
showOrUpdate();
144150
}
145151

146152
@Override
147153
public void onHostPause() {
148-
// do nothing
154+
// We dismiss the dialog and reconstitute it onHostResume
155+
dismiss();
149156
}
150157

151158
@Override
152159
public void onHostDestroy() {
153-
// Dismiss the dialog if it is present
154-
dismiss();
160+
// Drop the instance if the host is destroyed which will dismiss the dialog
161+
onDropInstance();
155162
}
156163

157164
@VisibleForTesting

0 commit comments

Comments
 (0)