From 311fdfdab8ec905f438e9a985902af0ecf49e2bf Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Mon, 10 Jun 2024 09:42:36 -0700 Subject: [PATCH] Expose unstable_loadFusebox API on Android (#44858) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44858 - Enables an opt-in to the Fusebox stack on Android for both architectures in open source. - Templates use of this opt-in in RNTester. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D58359907 --- .../ReactAndroid/api/ReactAndroid.api | 1 + .../DefaultNewArchitectureEntryPoint.kt | 33 +++++++++++++++++++ .../react/uiapp/RNTesterApplication.kt | 4 +++ 3 files changed, 38 insertions(+) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index f5564a0c71b639..91c59f9c54d5bc 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1995,6 +1995,7 @@ public final class com/facebook/react/defaults/DefaultNewArchitectureEntryPoint public static final fun load (ZZ)V public static final fun load (ZZZ)V public static synthetic fun load$default (ZZZILjava/lang/Object;)V + public static final fun unstable_loadFusebox (Z)V } public class com/facebook/react/defaults/DefaultReactActivityDelegate : com/facebook/react/ReactActivityDelegate { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt index ceabbe7392ab5b..27debe7b278ee6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt @@ -55,6 +55,10 @@ public object DefaultNewArchitectureEntryPoint { override fun batchRenderingUpdatesInEventLoop(): Boolean = true override fun useNativeViewConfigsInBridgelessMode(): Boolean = true + + // We need to assign this now as we can't call ReactNativeFeatureFlags.override() + // more than once. + override fun fuseboxEnabledDebug(): Boolean = isFuseboxEnabled }) } @@ -67,21 +71,25 @@ public object DefaultNewArchitectureEntryPoint { } private var privateFabricEnabled: Boolean = false + @JvmStatic public val fabricEnabled: Boolean get() = privateFabricEnabled private var privateTurboModulesEnabled: Boolean = false + @JvmStatic public val turboModulesEnabled: Boolean get() = privateTurboModulesEnabled private var privateConcurrentReactEnabled: Boolean = false + @JvmStatic public val concurrentReactEnabled: Boolean get() = privateConcurrentReactEnabled private var privateBridgelessEnabled: Boolean = false + @JvmStatic public val bridgelessEnabled: Boolean get() = privateBridgelessEnabled @@ -101,4 +109,29 @@ public object DefaultNewArchitectureEntryPoint { "bridgelessEnabled=true requires (turboModulesEnabled=true AND fabricEnabled=true) - Please update your DefaultNewArchitectureEntryPoint.load() parameters." else -> true to "" } + + /** + * If called, enables the new debugger stack (codename Fusebox). Must be called before + * {@link #load()}. + * + * @param isNewArchEnabled Please pass {@code BuildConfig.IS_NEW_ARCH_ENABLED} here. + */ + @JvmStatic + public fun unstable_loadFusebox( + isNewArchEnabled: Boolean, + ) { + isFuseboxEnabled = true + + if (!isNewArchEnabled) { + ReactNativeFeatureFlags.override( + object : ReactNativeFeatureFlagsDefaults() { + override fun fuseboxEnabledDebug(): Boolean = true + }) + } else { + // no-op as this will be taken care of inside load() instead + } + } + + /** Set to {@code true} if {@link #unstable_loadFusebox()} was called. */ + private var isFuseboxEnabled: Boolean = false } diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt index 901cf4666f80bc..d8acbfae2b9c49 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt @@ -136,6 +136,10 @@ class RNTesterApplication : Application(), ReactApplication { ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik) super.onCreate() SoLoader.init(this, /* native exopackage */ false) + + // [Experiment] Enable the new debugger stack (codename Fusebox) + // unstable_loadFusebox(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) + if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { load() }