From 8b2f324a9b915f504b237cad1281735b22684444 Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Tue, 26 Sep 2023 10:32:45 -0700 Subject: [PATCH] Enable Template with Bridgeless (#39661) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39661 Changelog: [Android][Changed] - Enable Template with Bridgeless Reviewed By: cortinico Differential Revision: D49464580 fbshipit-source-id: 26dd8e2a0b9a66421d58f147eed4d2fd28817dc7 --- .../com/facebook/react/flipper/ReactNativeFlipper.kt | 4 ++++ .../src/main/java/com/helloworld/MainApplication.kt | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/react-native/ReactAndroid/flipper-integration/src/debug/java/com/facebook/react/flipper/ReactNativeFlipper.kt b/packages/react-native/ReactAndroid/flipper-integration/src/debug/java/com/facebook/react/flipper/ReactNativeFlipper.kt index ecbef22f773105..e4bad1d94ed439 100644 --- a/packages/react-native/ReactAndroid/flipper-integration/src/debug/java/com/facebook/react/flipper/ReactNativeFlipper.kt +++ b/packages/react-native/ReactAndroid/flipper-integration/src/debug/java/com/facebook/react/flipper/ReactNativeFlipper.kt @@ -21,6 +21,7 @@ import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPl import com.facebook.react.ReactInstanceEventListener import com.facebook.react.ReactInstanceManager import com.facebook.react.bridge.ReactContext +import com.facebook.react.config.ReactFeatureFlags import com.facebook.react.modules.network.NetworkingModule /** @@ -30,6 +31,9 @@ import com.facebook.react.modules.network.NetworkingModule object ReactNativeFlipper { @JvmStatic fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) { + if (ReactFeatureFlags.enableBridgelessArchitecture) { + return + } if (FlipperUtils.shouldEnableFlipper(context)) { val client = AndroidFlipperClient.getInstance(context) client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())) diff --git a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt index 77a64826ad98c7..7314ad2aad3084 100644 --- a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt +++ b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt @@ -5,11 +5,15 @@ import com.facebook.react.PackageList import com.facebook.react.ReactApplication import com.facebook.react.ReactNativeHost import com.facebook.react.ReactPackage +import com.facebook.react.common.annotations.UnstableReactNativeAPI import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load +import com.facebook.react.defaults.DefaultReactHost import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.react.flipper.ReactNativeFlipper +import com.facebook.react.interfaces.ReactHost import com.facebook.soloader.SoLoader +@UnstableReactNativeAPI class MainApplication : Application(), ReactApplication { override val reactNativeHost: ReactNativeHost = @@ -28,6 +32,14 @@ class MainApplication : Application(), ReactApplication { override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED } + override val reactHost: ReactHost + get() = + DefaultReactHost.getDefaultReactHost( + context = this, + packageList = PackageList(this).packages, + jsMainModulePath = "index", + isHermesEnabled = BuildConfig.IS_HERMES_ENABLED) + override fun onCreate() { super.onCreate() SoLoader.init(this, false)