Skip to content

Commit

Permalink
Venice][Android] Migrate ReactModalHostView to use BridgelessReactCon…
Browse files Browse the repository at this point in the history
…text

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
  • Loading branch information
Lulu Wu authored and facebook-github-bot committed Dec 19, 2022
1 parent e71b094 commit 9f78517
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -159,7 +160,7 @@ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
}

public void onDropInstance() {
((ReactContext) getContext()).removeLifecycleEventListener(this);
((ThemedReactContext) getContext()).removeLifecycleEventListener(this);
dismiss();
}

Expand Down Expand Up @@ -237,7 +238,7 @@ public void onHostDestroy() {
}

private @Nullable Activity getCurrentActivity() {
return ((ReactContext) getContext()).getCurrentActivity();
return ((ThemedReactContext) getContext()).getCurrentActivity();
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 9f78517

@Ates83
Copy link

@Ates83 Ates83 commented on 9f78517 Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankyou👍

Please sign in to comment.