From 1b848c5ad0650ee2d34576a36348d0f3ae0cd108 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 5 May 2023 11:55:24 -0700 Subject: [PATCH] Introduce ReactInstanceDelegate.Builder (#37280) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37280 In this diff I'm introducing the ReactInstanceDelegate.Builder class that will be used to initialize ReactHost in Android This class is still under development, it is missing: - Tests - Documentantion for class and methods - Default objects for optional fields on ReactInstanceDelegate.Builder The goal of this diff is to introduce the class, test UnstableReactNativeAPI annotation and create a diff stack that shows the process to create a stable API in Android. bypass-github-export-checks changelog: [internal] internal Reviewed By: cortinico Differential Revision: D45509432 fbshipit-source-id: 7ae12f6b146491953a78edf02acf0e1ee8f8fce5 --- .../react/bridgeless/ReactInstanceDelegate.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactInstanceDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactInstanceDelegate.kt index 88b454b32ca..994efc17cad 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactInstanceDelegate.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactInstanceDelegate.kt @@ -16,6 +16,7 @@ import com.facebook.react.fabric.ReactNativeConfig import com.facebook.react.turbomodule.core.TurboModuleManager import com.facebook.react.turbomodule.core.TurboModuleManagerDelegate +/** TODO: add javadoc for class and methods */ @ThreadSafe interface ReactInstanceDelegate { val jSMainModulePath: String @@ -33,4 +34,26 @@ interface ReactInstanceDelegate { fun handleInstanceException(e: Exception) fun getReactNativeConfig(turboModuleManager: TurboModuleManager): ReactNativeConfig + + class ReactInstanceDelegateBase( + override val jSMainModulePath: String, + override val bindingsInstaller: BindingsInstaller, + override val reactPackages: List, + private val jsBundleLoader: JSBundleLoader, + private val turboModuleManagerDelegate: TurboModuleManagerDelegate, + private val jsEngineInstance: JSEngineInstance, + private val reactNativeConfig: ReactNativeConfig, + private val exceptionHandler: (Exception) -> Unit = {} + ) : ReactInstanceDelegate { + override fun getJSBundleLoader(context: Context) = jsBundleLoader + + override fun getTurboModuleManagerDelegate(context: ReactApplicationContext) = + turboModuleManagerDelegate + + override fun getJSEngineInstance(context: ReactApplicationContext) = jsEngineInstance + + override fun getReactNativeConfig(turboModuleManager: TurboModuleManager) = reactNativeConfig + + override fun handleInstanceException(e: Exception) = exceptionHandler(e) + } }