From 642705e9a36244da759976f836a74ccc267f17e8 Mon Sep 17 00:00:00 2001 From: David Vacca <515103+mdvacca@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:09:46 -0800 Subject: [PATCH 1/3] Remove jsBundleLoader from DefaultReactHost.getDefaultReactHost Summary: jsBundleLoader parameter was added into DefaultReactHost.getDefaultReactHost but we decided to revert this change. We want to keep DefaultReactHost.getDefaultReactHost as simple as possible and we don't want to include this change in 0.77 changelog: [Android][Breaking] Remove jsBundleLoader from DefaultReactHost.getDefaultReactHost() Differential Revision: D66131197 --- .../ReactAndroid/api/ReactAndroid.api | 8 +++---- .../react/defaults/DefaultReactHost.kt | 24 ++++++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) 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/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) } From 2d80c36860d4ec5cddaedb0c73a2223bf0cbc1f9 Mon Sep 17 00:00:00 2001 From: David Vacca <515103+mdvacca@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:09:46 -0800 Subject: [PATCH 2/3] Make SurfaceDelegate and SurfaceDelegateFactory NullSafe Summary: Make SurfaceDelegate and SurfaceDelegateFactory NullSafe changelog: [internal] internal Differential Revision: D66134454 --- .../main/java/com/facebook/react/common/SurfaceDelegate.java | 3 +++ .../com/facebook/react/common/SurfaceDelegateFactory.java | 5 +++++ 2 files changed, 8 insertions(+) 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 index feed32596250..76a5edf63053 100644 --- 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 @@ -7,11 +7,15 @@ package com.facebook.react.common; +import androidx.annotation.Nullable; +import com.facebook.infer.annotation.Nullsafe; + /** * 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. */ +@Nullsafe(Nullsafe.Mode.LOCAL) public interface SurfaceDelegateFactory { /** * Create a {@link SurfaceDelegate} instance which is used to interact with a surface of platform @@ -20,5 +24,6 @@ public interface SurfaceDelegateFactory { * @param moduleName the module name that will be using the surface * @return {@link SurfaceDelegate} instance */ + @Nullable SurfaceDelegate createSurfaceDelegate(String moduleName); } From 821a907c741227c28aa065630a44bc58369ed445 Mon Sep 17 00:00:00 2001 From: David Vacca <515103+mdvacca@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:09:46 -0800 Subject: [PATCH 3/3] MigrateSurfaceDelegateFactory to Kotlin Summary: MigrateSurfaceDelegateFactory to Kotlin changelog: [internal] internal Differential Revision: D66133186 --- .../react/common/SurfaceDelegateFactory.java | 29 ------------------- .../react/common/SurfaceDelegateFactory.kt | 22 ++++++++++++++ 2 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.kt 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 76a5edf63053..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/SurfaceDelegateFactory.java +++ /dev/null @@ -1,29 +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; - -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; - -/** - * 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. - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -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 - */ - @Nullable - 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? +}