Have Modal dismiss Dialog when the ReactInstance goes away

Reviewed By: angelahess

Differential Revision: D3252808

fb-gh-sync-id: 1f3085412f409581f161cf2151b251e818851d84
fbshipit-source-id: 1f3085412f409581f161cf2151b251e818851d84
This commit is contained in:
Dave Miller 2016-05-03 13:28:00 -07:00 коммит произвёл Facebook Github Bot 8
Родитель 0a7a228fbb
Коммит 20d53b1f23
1 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -24,6 +24,7 @@ import android.view.WindowManager;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.react.R; import com.facebook.react.R;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.uimanager.JSTouchDispatcher; import com.facebook.react.uimanager.JSTouchDispatcher;
@ -44,7 +45,7 @@ import com.facebook.react.views.view.ReactViewGroup;
* DialogRootViewGroup were part of the hierarchy. Therefore, we forward all view changes * DialogRootViewGroup were part of the hierarchy. Therefore, we forward all view changes
* around addition and removal of views to the DialogRootViewGroup. * around addition and removal of views to the DialogRootViewGroup.
*/ */
public class ReactModalHostView extends ViewGroup { public class ReactModalHostView extends ViewGroup implements LifecycleEventListener {
// This listener is called when the user presses KeyEvent.KEYCODE_BACK // This listener is called when the user presses KeyEvent.KEYCODE_BACK
// An event is then passed to JS which can either close or not close the Modal by setting the // An event is then passed to JS which can either close or not close the Modal by setting the
@ -66,6 +67,7 @@ public class ReactModalHostView extends ViewGroup {
public ReactModalHostView(Context context) { public ReactModalHostView(Context context) {
super(context); super(context);
((ReactContext) context).addLifecycleEventListener(this);
mHostView = new DialogRootViewGroup(context); mHostView = new DialogRootViewGroup(context);
} }
@ -136,6 +138,22 @@ public class ReactModalHostView extends ViewGroup {
mPropertyRequiresNewDialog = true; mPropertyRequiresNewDialog = true;
} }
@Override
public void onHostResume() {
// do nothing
}
@Override
public void onHostPause() {
// do nothing
}
@Override
public void onHostDestroy() {
// Dismiss the dialog if it is present
dismiss();
}
@VisibleForTesting @VisibleForTesting
public @Nullable Dialog getDialog() { public @Nullable Dialog getDialog() {
return mDialog; return mDialog;