Skip to content

Commit

Permalink
Allow customization of BridgelessDevSupportManager for Expo Go (faceb…
Browse files Browse the repository at this point in the history
…ook#46914)

Summary:

This is a WIP

Changelog:
[Android] [Changed] - Allow customization of BridgelessDevSupportManager for Expo Go

Reviewed By: rshest

Differential Revision: D64105790
  • Loading branch information
cortinico authored and facebook-github-bot committed Oct 9, 2024
1 parent 0449630 commit f236a98
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
10 changes: 10 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -3859,6 +3859,15 @@ public final class com/facebook/react/runtime/BridgelessCatalystInstance : com/f
public fun setTurboModuleRegistry (Lcom/facebook/react/internal/turbomodule/core/interfaces/TurboModuleRegistry;)V
}

public class com/facebook/react/runtime/BridgelessDevSupportManager : com/facebook/react/devsupport/DevSupportManagerBase {
public fun <init> (Lcom/facebook/react/runtime/ReactHostImpl;Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZLcom/facebook/react/devsupport/interfaces/RedBoxHandler;Lcom/facebook/react/devsupport/interfaces/DevBundleDownloadListener;ILjava/util/Map;Lcom/facebook/react/common/SurfaceDelegateFactory;Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;Lcom/facebook/react/devsupport/interfaces/PausedInDebuggerOverlayManager;)V
public fun <init> (Lcom/facebook/react/runtime/ReactHostImpl;Landroid/content/Context;Ljava/lang/String;)V
public static fun createInstanceDevHelper (Lcom/facebook/react/runtime/ReactHostImpl;)Lcom/facebook/react/devsupport/ReactInstanceDevHelper;
protected fun getUniqueTag ()Ljava/lang/String;
public fun handleReloadJS ()V
public fun loadSplitBundleFromServer (Ljava/lang/String;Lcom/facebook/react/devsupport/interfaces/DevSplitBundleCallback;)V
}

public class com/facebook/react/runtime/CoreReactPackage$$ReactModuleInfoProvider : com/facebook/react/module/model/ReactModuleInfoProvider {
public fun <init> ()V
public fun getReactModuleInfos ()Ljava/util/Map;
Expand Down Expand Up @@ -3897,6 +3906,7 @@ public class com/facebook/react/runtime/ReactHostImpl : com/facebook/react/React
public fun onHostResume (Landroid/app/Activity;Lcom/facebook/react/modules/core/DefaultHardwareBackBtnHandler;)V
public fun onNewIntent (Landroid/content/Intent;)V
public fun onWindowFocusChange (Z)V
public fun overrideDevSupportManager (Lcom/facebook/react/devsupport/interfaces/DevSupportManager;)V
public fun reload (Ljava/lang/String;)Lcom/facebook/react/interfaces/TaskInterface;
public fun removeBeforeDestroyListener (Lkotlin/jvm/functions/Function0;)V
public fun removeReactInstanceEventListener (Lcom/facebook/react/ReactInstanceEventListener;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package com.facebook.react.common.annotations

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,44 @@
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JavaJSExecutor;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.SurfaceDelegateFactory;
import com.facebook.react.common.annotations.FrameworkAPI;
import com.facebook.react.devsupport.DevSupportManagerBase;
import com.facebook.react.devsupport.HMRClient;
import com.facebook.react.devsupport.ReactInstanceDevHelper;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.packagerconnection.RequestHandler;
import com.facebook.react.runtime.internal.bolts.Continuation;
import com.facebook.react.runtime.internal.bolts.Task;
import java.util.Map;

/**
* An implementation of {@link com.facebook.react.devsupport.interfaces.DevSupportManager} that
* extends the functionality in {@link DevSupportManagerBase} with some additional, more flexible
* APIs for asynchronously loading the JS bundle.
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
class BridgelessDevSupportManager extends DevSupportManagerBase {
public class BridgelessDevSupportManager extends DevSupportManagerBase {

private final ReactHostImpl mReactHost;

@OptIn(markerClass = FrameworkAPI.class)
public BridgelessDevSupportManager(
ReactHostImpl host, Context context, @Nullable String packagerPathForJSBundleName) {
super(
this(
host,
context.getApplicationContext(),
createInstanceDevHelper(host),
packagerPathForJSBundleName,
Expand All @@ -50,6 +61,38 @@ public BridgelessDevSupportManager(
null /* surfaceDelegateFactory */,
null /* devLoadingViewManager */,
null /* pausedInDebuggerOverlayManager */);
}

/**
* This constructor mirrors the same constructor we have for {@link BridgeDevSupportManager} and
* is used by Expo/ExpoGo to customize the DevMenu on Bridgeless mode.
*/
@FrameworkAPI
public BridgelessDevSupportManager(
ReactHostImpl host,
Context applicationContext,
ReactInstanceDevHelper reactInstanceManagerHelper,
@Nullable String packagerPathForJSBundleName,
boolean enableOnCreate,
@Nullable RedBoxHandler redBoxHandler,
@Nullable DevBundleDownloadListener devBundleDownloadListener,
int minNumShakes,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
@Nullable DevLoadingViewManager devLoadingViewManager,
@Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager) {
super(
applicationContext,
reactInstanceManagerHelper,
packagerPathForJSBundleName,
enableOnCreate,
redBoxHandler,
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory,
devLoadingViewManager,
pausedInDebuggerOverlayManager);
mReactHost = host;
}

Expand Down Expand Up @@ -102,7 +145,7 @@ public void handleReloadJS() {
mReactHost.reload("BridgelessDevSupportManager.handleReloadJS()");
}

private static ReactInstanceDevHelper createInstanceDevHelper(final ReactHostImpl reactHost) {
public static ReactInstanceDevHelper createInstanceDevHelper(final ReactHostImpl reactHost) {
return new ReactInstanceDevHelper() {
@Override
public void onReloadWithJSDebugger(JavaJSExecutor.Factory proxyExecutorFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class ReactHostImpl implements ReactHost {
private final Context mContext;
private final ReactHostDelegate mReactHostDelegate;
private final ComponentFactory mComponentFactory;
private final DevSupportManager mDevSupportManager;
private DevSupportManager mDevSupportManager;
private final Executor mBGExecutor;
private final Executor mUIExecutor;
private final Set<ReactSurfaceImpl> mAttachedSurfaces = new HashSet<>();
Expand Down Expand Up @@ -165,6 +165,26 @@ public ReactHostImpl(
Executor uiExecutor,
boolean allowPackagerServerAccess,
boolean useDevSupport) {
this(
context,
delegate,
componentFactory,
bgExecutor,
uiExecutor,
allowPackagerServerAccess,
useDevSupport,
null);
}

public ReactHostImpl(
Context context,
ReactHostDelegate delegate,
ComponentFactory componentFactory,
Executor bgExecutor,
Executor uiExecutor,
boolean allowPackagerServerAccess,
boolean useDevSupport,
@Nullable DevSupportManager devSupportManager) {
mContext = context;
mReactHostDelegate = delegate;
mComponentFactory = componentFactory;
Expand All @@ -173,13 +193,16 @@ public ReactHostImpl(
mMemoryPressureRouter = new MemoryPressureRouter(context);
mAllowPackagerServerAccess = allowPackagerServerAccess;
mUseDevSupport = useDevSupport;

if (mUseDevSupport) {
mDevSupportManager =
new BridgelessDevSupportManager(
ReactHostImpl.this, mContext, mReactHostDelegate.getJsMainModulePath());
} else {
mDevSupportManager = new ReleaseDevSupportManager();
mDevSupportManager = devSupportManager;

if (devSupportManager == null) {
if (mUseDevSupport) {
mDevSupportManager =
new BridgelessDevSupportManager(
ReactHostImpl.this, mContext, mReactHostDelegate.getJsMainModulePath());
} else {
mDevSupportManager = new ReleaseDevSupportManager();
}
}
}

Expand Down

0 comments on commit f236a98

Please sign in to comment.