Support custom DevSupportManager (#31841)

Summary:
to open possibilities for some DX enhancement, the pr introduces `DevSupportManagerFactory` customization. applications could implement a different DevSupportManager in ReactNativeHost.

## Changelog

[Internal] [Added] - Support custom DevSupportManager

Pull Request resolved: https://github.com/facebook/react-native/pull/31841

Test Plan: this pr just introduces some new interfaces and should not break existing functionalities.

Reviewed By: RSNara

Differential Revision: D30878134

Pulled By: yungsters

fbshipit-source-id: ccdf798caa322b07a876da8312b97002da057388
This commit is contained in:
Kudo Chien
2021-09-22 10:33:14 -07:00
committed by Facebook GitHub Bot
parent 88021894f2
commit 369b28ce01
5 changed files with 127 additions and 74 deletions
@@ -22,6 +22,8 @@ import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.devsupport.DefaultDevSupportManagerFactory;
import com.facebook.react.devsupport.DevSupportManagerFactory;
import com.facebook.react.devsupport.RedBoxHandler;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
@@ -45,6 +47,7 @@ public class ReactInstanceManagerBuilder {
private @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener;
private @Nullable Application mApplication;
private boolean mUseDeveloperSupport;
private @Nullable DevSupportManagerFactory mDevSupportManagerFactory;
private boolean mRequireActivity;
private @Nullable LifecycleState mInitialLifecycleState;
private @Nullable UIImplementationProvider mUIImplementationProvider;
@@ -172,6 +175,16 @@ public class ReactInstanceManagerBuilder {
return this;
}
/**
* Set the custom {@link DevSupportManagerFactory}. If not set, will use {@link
* DefaultDevSupportManagerFactory}.
*/
public ReactInstanceManagerBuilder setDevSupportManagerFactory(
final DevSupportManagerFactory devSupportManagerFactory) {
mDevSupportManagerFactory = devSupportManagerFactory;
return this;
}
/**
* When {@code false}, indicates that correct usage of React Native will NOT involve an Activity.
* For the vast majority of Android apps in the ecosystem, this will not need to change. Unless
@@ -294,6 +307,9 @@ public class ReactInstanceManagerBuilder {
mJSMainModulePath,
mPackages,
mUseDeveloperSupport,
mDevSupportManagerFactory == null
? new DefaultDevSupportManagerFactory()
: mDevSupportManagerFactory,
mRequireActivity,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),