diff --git a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt index 4eb6401b35b..131804140ee 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt +++ b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultComponentsRegistry.kt @@ -15,8 +15,8 @@ import com.facebook.react.fabric.ComponentFactory * A utility class that provides users a ComponentRegistry they can customize with a C++ * implementation of its native methods. * - * This class works together with the [DefaultNativeEntryPoint] and it's C++ implementation is - * hosted inside the React Native framework + * This class works together with the [DefaultNewArchitectureEntryPoint] and it's C++ implementation + * is hosted inside the React Native framework */ @DoNotStrip class DefaultComponentsRegistry diff --git a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNativeEntryPoint.kt b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNativeEntryPoint.kt deleted file mode 100644 index 02db04658ae..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNativeEntryPoint.kt +++ /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.defaults - -import com.facebook.soloader.SoLoader - -/** - * A utility class that serves as an entry point for users to register all the custom Fabric - * Components and Turbo Native Modules. - * - * This class needs to be invoked as `DefaultNativeEntryPoint.load("...")` by passing the name of - * the dynamic library to load. - * - * By default it loads a library called `appmodules`. `appmodules` is a convention used to refer to - * the application dynamic library. If changed here should be updated also inside the template. - */ -object DefaultNativeEntryPoint { - @JvmStatic - @JvmOverloads - fun load(dynamicLibraryName: String = "appmodules") { - SoLoader.loadLibrary("react_newarchdefaults") - SoLoader.loadLibrary(dynamicLibraryName) - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt new file mode 100644 index 00000000000..f3552517f75 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt @@ -0,0 +1,49 @@ +/* + * 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.defaults + +import com.facebook.react.config.ReactFeatureFlags +import com.facebook.soloader.SoLoader + +/** + * A utility class that serves as an entry point for users setup the New Architecture. + * + * This class needs to be invoked as `DefaultNewArchitectureEntryPoint.load(...)` by passing a + * series of optional parameters. + * + * By default it loads a library called `appmodules`. `appmodules` is a convention used to refer to + * the application dynamic library. If changed here should be updated also inside the template. + * + * By default it also enables both TurboModules, Fabric and Concurrent React (aka React 18) + */ +object DefaultNewArchitectureEntryPoint { + @JvmStatic + @JvmOverloads + fun load( + dynamicLibraryName: String = "appmodules", + turboModulesEnabled: Boolean = true, + fabricEnabled: Boolean = true, + concurrentReactEnabled: Boolean = true + ) { + ReactFeatureFlags.useTurboModules = turboModulesEnabled + ReactFeatureFlags.enableFabricRenderer = fabricEnabled + + this.fabricEnabled = fabricEnabled + this.turboModulesEnabled = turboModulesEnabled + this.concurrentReactEnabled = concurrentReactEnabled + + SoLoader.loadLibrary("react_newarchdefaults") + SoLoader.loadLibrary(dynamicLibraryName) + } + + @JvmStatic var fabricEnabled: Boolean = false + + @JvmStatic var turboModulesEnabled: Boolean = false + + @JvmStatic var concurrentReactEnabled: Boolean = false +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt index 714bb654c77..ac1fd1a4c7d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt +++ b/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultTurboModuleManagerDelegate.kt @@ -17,8 +17,8 @@ import com.facebook.react.bridge.ReactApplicationContext * A utility class that allows you to simplify the setup of a * [ReactPackageTurboModuleManagerDelegate] for new apps in Open Source. * - * This class works together with the [DefaultNativeEntryPoint] and it's C++ implementation is - * hosted inside the React Native framework + * This class works together with the [DefaultNewArchitectureEntryPoint] and it's C++ implementation + * is hosted inside the React Native framework */ class DefaultTurboModuleManagerDelegate private constructor(context: ReactApplicationContext, packages: List) : diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java index 143765e1984..da9cba600d3 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterActivity.java @@ -11,6 +11,7 @@ import android.os.Bundle; import androidx.annotation.Nullable; import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; import com.facebook.react.defaults.DefaultReactActivityDelegate; public class RNTesterActivity extends ReactActivity { @@ -23,8 +24,8 @@ public class RNTesterActivity extends ReactActivity { super( activity, mainComponentName, - true, // fabricEnabled - true // concurrentRootEnabled + DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled + DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled ); this.mActivity = activity; } diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java index cdc5ac62828..5012a0e45e4 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -17,7 +17,7 @@ import com.facebook.react.TurboReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.config.ReactFeatureFlags; -import com.facebook.react.defaults.DefaultNativeEntryPoint; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; import com.facebook.react.defaults.DefaultReactNativeHost; import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; @@ -119,11 +119,10 @@ public class RNTesterApplication extends Application implements ReactApplication @Override public void onCreate() { - ReactFeatureFlags.useTurboModules = true; ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik); super.onCreate(); SoLoader.init(this, /* native exopackage */ false); - DefaultNativeEntryPoint.load(); + DefaultNewArchitectureEntryPoint.load(); ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); } diff --git a/template/android/app/src/main/java/com/helloworld/MainActivity.java b/template/android/app/src/main/java/com/helloworld/MainActivity.java index d66f035735a..96fcdf2d7ca 100644 --- a/template/android/app/src/main/java/com/helloworld/MainActivity.java +++ b/template/android/app/src/main/java/com/helloworld/MainActivity.java @@ -2,6 +2,7 @@ package com.helloworld; import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; import com.facebook.react.defaults.DefaultReactActivityDelegate; public class MainActivity extends ReactActivity { @@ -17,8 +18,8 @@ public class MainActivity extends ReactActivity { /** * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link - * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent Root (aka - * React 18) with two boolean flags. + * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React + * (aka React 18) with two boolean flags. */ @Override protected ReactActivityDelegate createReactActivityDelegate() { @@ -26,9 +27,9 @@ public class MainActivity extends ReactActivity { this, getMainComponentName(), // If you opted-in for the New Architecture, we enable the Fabric Renderer. - BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, // fabricEnabled - // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). - BuildConfig.IS_NEW_ARCHITECTURE_ENABLED // concurrentRootEnabled + DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled + // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). + DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled ); } } diff --git a/template/android/app/src/main/java/com/helloworld/MainApplication.java b/template/android/app/src/main/java/com/helloworld/MainApplication.java index ccf1addb2b9..be113ec4396 100644 --- a/template/android/app/src/main/java/com/helloworld/MainApplication.java +++ b/template/android/app/src/main/java/com/helloworld/MainApplication.java @@ -5,8 +5,7 @@ import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; -import com.facebook.react.config.ReactFeatureFlags; -import com.facebook.react.defaults.DefaultNativeEntryPoint; +import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; import com.facebook.react.defaults.DefaultReactNativeHost; import com.facebook.soloader.SoLoader; import java.util.List; @@ -50,10 +49,8 @@ public class MainApplication extends Application implements ReactApplication { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - // If you opted-in for the New Architecture, we enable the TurboModule system - // and load the native entry point for this app. - ReactFeatureFlags.useTurboModules = true; - DefaultNativeEntryPoint.load(); + // If you opted-in for the New Architecture, we load the native entry point for this app. + DefaultNewArchitectureEntryPoint.load(); } ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); }