From 9f78517d6401f3a7ece453825a059a13b73f6140 Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Mon, 19 Dec 2022 12:45:09 -0800 Subject: [PATCH] Venice][Android] Migrate ReactModalHostView to use BridgelessReactContext Summary: - Use ThemedReactContext explicitly to reduce confusion, "addLifecycleEventListener()" and "removeLifecycleEventListener" should be forced to call on ThemedReactContext - Migrate "getNativeModule" and "handleException" calls from ThemedReactContext to ThemedReactContext.getReactApplicationContext Changelog: [Android][Changed] - Use ThemedReactContext explicitly to reduce confusion Reviewed By: mdvacca Differential Revision: D42101979 fbshipit-source-id: be34b7397ccf4f58477bab6cfa8c58eedd99e225 --- .../react/views/modal/ReactModalHostView.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 b8046f5da76c21..9f408a7668c18f 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 @@ -41,6 +41,7 @@ import com.facebook.react.uimanager.JSTouchDispatcher; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.RootView; +import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.views.common.ContextUtils; @@ -87,9 +88,9 @@ public interface OnRequestCloseListener { private @Nullable DialogInterface.OnShowListener mOnShowListener; private @Nullable OnRequestCloseListener mOnRequestCloseListener; - public ReactModalHostView(Context context) { + public ReactModalHostView(ThemedReactContext context) { super(context); - ((ReactContext) context).addLifecycleEventListener(this); + context.addLifecycleEventListener(this); mHostView = new DialogRootViewGroup(context); } @@ -159,7 +160,7 @@ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { } public void onDropInstance() { - ((ReactContext) getContext()).removeLifecycleEventListener(this); + ((ThemedReactContext) getContext()).removeLifecycleEventListener(this); dismiss(); } @@ -237,7 +238,7 @@ public void onHostDestroy() { } private @Nullable Activity getCurrentActivity() { - return ((ReactContext) getContext()).getCurrentActivity(); + return ((ThemedReactContext) getContext()).getCurrentActivity(); } /** @@ -460,7 +461,9 @@ private void updateFirstChildView() { @Override public void runGuarded() { UIManagerModule uiManager = - (getReactContext()).getNativeModule(UIManagerModule.class); + getReactContext() + .getReactApplicationContext() + .getNativeModule(UIManagerModule.class); if (uiManager == null) { return; @@ -520,11 +523,11 @@ public void addView(View child, int index, LayoutParams params) { @Override public void handleException(Throwable t) { - getReactContext().handleException(new RuntimeException(t)); + getReactContext().getReactApplicationContext().handleException(new RuntimeException(t)); } - private ReactContext getReactContext() { - return (ReactContext) getContext(); + private ThemedReactContext getReactContext() { + return (ThemedReactContext) getContext(); } @Override