Skip to content

Commit

Permalink
Register TurboModuleManagerDelegate builders without JSIModules
Browse files Browse the repository at this point in the history
Summary:
How does an application register a TurboModuleManagerDelegate with ReactInstanceManager?
1. Call ReactInstanceManagerBuilder.setReactPackageTurboModuleManagerDelegateBuilder(ReactPackageTurboModuleManagerDelegate.Builder)
2. Override ReactNativeHost.getReactPackageTurboModuleManagerDelegateBuilder()

Changelog: [Android][Added] - Introduce API to allow applications to register TurboModuleManagerDelegates with ReactInstanceManager

Reviewed By: mdvacca

Differential Revision: D26193055

fbshipit-source-id: bf82e63e6ab1c0c8f12bada92ac6852c992ec9cb
  • Loading branch information
RSNara authored and facebook-github-bot committed Feb 3, 2021
1 parent 48e4e34 commit eb7e89e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public interface ReactInstanceEventListener {
private final MemoryPressureRouter mMemoryPressureRouter;
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private final @Nullable JSIModulePackage mJSIModulePackage;
private final @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
private List<ViewManager> mViewManagers;

private class ReactContextInitParams {
Expand Down Expand Up @@ -218,7 +219,8 @@ public static ReactInstanceManagerBuilder builder() {
int minNumShakes,
int minTimeLeftInFrameForNonBatchedOperationMs,
@Nullable JSIModulePackage jsiModulePackage,
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers) {
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
@Nullable ReactPackageTurboModuleManagerDelegate.Builder tmmDelegateBuilder) {
FLog.d(TAG, "ReactInstanceManager.ctor()");
initializeSoLoaderIfNecessary(applicationContext);

Expand Down Expand Up @@ -249,6 +251,7 @@ public static ReactInstanceManagerBuilder builder() {
mLifecycleState = initialLifecycleState;
mMemoryPressureRouter = new MemoryPressureRouter(applicationContext);
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
mTMMDelegateBuilder = tmmDelegateBuilder;
synchronized (mPackages) {
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.RN_CORE, "RNCore: Use Split Packages");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ReactInstanceManagerBuilder {
private int mMinTimeLeftInFrameForNonBatchedOperationMs = -1;
private @Nullable JSIModulePackage mJSIModulesPackage;
private @Nullable Map<String, RequestHandler> mCustomPackagerCommandHandlers;
private @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;

/* package protected */ ReactInstanceManagerBuilder() {}

Expand Down Expand Up @@ -224,6 +225,12 @@ public ReactInstanceManagerBuilder setCustomPackagerCommandHandlers(
return this;
}

public ReactInstanceManagerBuilder setReactPackageTurboModuleManagerDelegateBuilder(
@Nullable ReactPackageTurboModuleManagerDelegate.Builder builder) {
mTMMDelegateBuilder = builder;
return this;
}

/**
* Instantiates a new {@link ReactInstanceManager}. Before calling {@code build}, the following
* must be called:
Expand Down Expand Up @@ -286,7 +293,8 @@ public ReactInstanceManager build() {
mMinNumShakes,
mMinTimeLeftInFrameForNonBatchedOperationMs,
mJSIModulesPackage,
mCustomPackagerCommandHandlers);
mCustomPackagerCommandHandlers,
mTMMDelegateBuilder);
}

private JavaScriptExecutorFactory getDefaultJSExecutorFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ protected ReactInstanceManager createReactInstanceManager() {
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setUIImplementationProvider(getUIImplementationProvider())
.setJSIModulesPackage(getJSIModulePackage())
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE);
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
.setReactPackageTurboModuleManagerDelegateBuilder(
getReactPackageTurboModuleManagerDelegateBuilder());

for (ReactPackage reactPackage : getPackages()) {
builder.addPackage(reactPackage);
Expand All @@ -99,6 +101,11 @@ protected ReactInstanceManager createReactInstanceManager() {
return null;
}

protected @Nullable ReactPackageTurboModuleManagerDelegate.Builder
getReactPackageTurboModuleManagerDelegateBuilder() {
return null;
}

protected final Application getApplication() {
return mApplication;
}
Expand Down

0 comments on commit eb7e89e

Please sign in to comment.