diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 16be4f9f3989..a55f39188d03 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2037,10 +2037,10 @@ public class com/facebook/react/defaults/DefaultReactActivityDelegate : com/face public final class com/facebook/react/defaults/DefaultReactHost { public static final field INSTANCE Lcom/facebook/react/defaults/DefaultReactHost; public static final fun getDefaultReactHost (Landroid/content/Context;Lcom/facebook/react/ReactNativeHost;)Lcom/facebook/react/ReactHost; - public static final fun getDefaultReactHost (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;Lcom/facebook/react/bridge/JSBundleLoader;)Lcom/facebook/react/ReactHost; - public static final fun getDefaultReactHost (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;Lcom/facebook/react/bridge/JSBundleLoader;Lkotlin/jvm/functions/Function1;)Lcom/facebook/react/ReactHost; - public static synthetic fun getDefaultReactHost$default (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;Lcom/facebook/react/bridge/JSBundleLoader;ILjava/lang/Object;)Lcom/facebook/react/ReactHost; - public static synthetic fun getDefaultReactHost$default (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;Lcom/facebook/react/bridge/JSBundleLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/facebook/react/ReactHost; + public static final fun getDefaultReactHost (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;)Lcom/facebook/react/ReactHost; + public static final fun getDefaultReactHost (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;Lkotlin/jvm/functions/Function1;)Lcom/facebook/react/ReactHost; + public static synthetic fun getDefaultReactHost$default (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;ILjava/lang/Object;)Lcom/facebook/react/ReactHost; + public static synthetic fun getDefaultReactHost$default (Landroid/content/Context;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZLjava/util/List;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/facebook/react/ReactHost; } public abstract class com/facebook/react/defaults/DefaultReactNativeHost : com/facebook/react/ReactNativeHost { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.java index a6ba792926eb..6ba362aa2b42 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegate.java @@ -7,6 +7,8 @@ package com.facebook.react.common; +import com.facebook.infer.annotation.Nullsafe; + /** * Interface for handling a surface in React Native. In mobile platform a surface can be any * container that holds some {@link View}. For example, a Dialog can be a surface to wrap content @@ -14,6 +16,7 @@ * requires custom logic to show/hide. NativeModules requires a surface will delegate interactions * with the surface to a SurfaceDelegate. */ +@Nullsafe(Nullsafe.Mode.LOCAL) public interface SurfaceDelegate { /** * Create the React content view that uses the appKey as the React application name diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.java deleted file mode 100644 index feed32596250..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.common; - -/** - * Factory to create a {@link SurfaceDelegate}. The moduleName is needed to help the factory decide - * which surface to return {@link SurfaceDelegate} that the given module should use to interact - * with. - */ -public interface SurfaceDelegateFactory { - /** - * Create a {@link SurfaceDelegate} instance which is used to interact with a surface of platform - * the app is running in. - * - * @param moduleName the module name that will be using the surface - * @return {@link SurfaceDelegate} instance - */ - SurfaceDelegate createSurfaceDelegate(String moduleName); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.kt new file mode 100644 index 000000000000..d1675bc7dc3d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +package com.facebook.react.common + +/** + * Factory to create a [SurfaceDelegate]. The moduleName is needed to help the factory decide which + * surface to return [SurfaceDelegate] that the given module should use to interact with. + */ +public fun interface SurfaceDelegateFactory { + /** + * Create a [SurfaceDelegate] instance which is used to interact with a surface of platform the + * app is running in. + * + * @param moduleName the module name that will be using the surface + * @return [SurfaceDelegate] instance + */ + public fun createSurfaceDelegate(moduleName: String): SurfaceDelegate? +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt index 1c17bc6e79c6..f0d0cdcaccb0 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt @@ -61,7 +61,6 @@ public object DefaultReactHost { isHermesEnabled: Boolean = true, useDevSupport: Boolean = ReactBuildConfig.DEBUG, cxxReactPackageProviders: List<(ReactContext) -> CxxReactPackage> = emptyList(), - jsBundleLoader: JSBundleLoader? = null, ): ReactHost = getDefaultReactHost( context, @@ -71,8 +70,7 @@ public object DefaultReactHost { jsBundleFilePath, isHermesEnabled, useDevSupport, - cxxReactPackageProviders, - jsBundleLoader) { + cxxReactPackageProviders) { throw it } @@ -107,22 +105,20 @@ public object DefaultReactHost { isHermesEnabled: Boolean = true, useDevSupport: Boolean = ReactBuildConfig.DEBUG, cxxReactPackageProviders: List<(ReactContext) -> CxxReactPackage> = emptyList(), - jsBundleLoader: JSBundleLoader? = null, exceptionHandler: (Exception) -> Unit = { throw it }, ): ReactHost { if (reactHost == null) { val bundleLoader = - jsBundleLoader - ?: if (jsBundleFilePath != null) { - if (jsBundleFilePath.startsWith("assets://")) { - JSBundleLoader.createAssetLoader(context, jsBundleFilePath, true) - } else { - JSBundleLoader.createFileLoader(jsBundleFilePath) - } - } else { - JSBundleLoader.createAssetLoader(context, "assets://$jsBundleAssetPath", true) - } + if (jsBundleFilePath != null) { + if (jsBundleFilePath.startsWith("assets://")) { + JSBundleLoader.createAssetLoader(context, jsBundleFilePath, true) + } else { + JSBundleLoader.createFileLoader(jsBundleFilePath) + } + } else { + JSBundleLoader.createAssetLoader(context, "assets://$jsBundleAssetPath", true) + } val jsRuntimeFactory = if (isHermesEnabled) HermesInstance() else JSCInstance() val defaultTmmDelegateBuilder = DefaultTurboModuleManagerDelegate.Builder() cxxReactPackageProviders.forEach { defaultTmmDelegateBuilder.addCxxReactPackage(it) }