mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce the DefaultMainActivityDelegate to simplify enabling/disabling Fabric for new apps. (#34446)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34446 I'm adding another class to the .defaults package. This will take care of setting the RootView with Fabric enabled/disabled as well as controlling concurrent root. Changelog: [Android] [Added] - Introduce the DefaultMainActivityDelegate to simplify enabling/disabling Fabric for new apps. Reviewed By: cipolleschi Differential Revision: D38823181 fbshipit-source-id: 2293b9df6b0d8fa79695bd52a8e0bb46b44c43c8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0f0d52067c
commit
dd6d5a78a3
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.ReactActivity
|
||||
import com.facebook.react.ReactActivityDelegate
|
||||
import com.facebook.react.ReactRootView
|
||||
|
||||
/**
|
||||
* A utility class that allows you to simplify the setup of a [ReactActivityDelegate] for new apps
|
||||
* in Open Source.
|
||||
*
|
||||
* Specifically, with this class you can simply control if Fabric and Concurrent Root are enabled
|
||||
* for an Activity using the boolean flags in the constructor.
|
||||
*
|
||||
* @param fabricEnabled Whether Fabric should be enabled for the RootView of this Activity.
|
||||
* @param concurrentRootEnabled Whether ConcurrentRoot (aka React 18) should be enabled for the
|
||||
* RootView of this Activity.
|
||||
*/
|
||||
open class DefaultReactActivityDelegate(
|
||||
activity: ReactActivity,
|
||||
mainComponentName: String,
|
||||
val fabricEnabled: Boolean = false,
|
||||
val concurrentRootEnabled: Boolean = false
|
||||
) : ReactActivityDelegate(activity, mainComponentName) {
|
||||
|
||||
/**
|
||||
* Override this method to enable Concurrent Root on the surface for this Activity. See:
|
||||
* https://reactjs.org/blog/2022/03/29/react-v18.html
|
||||
*
|
||||
* This requires to be rendering on Fabric (i.e. on the New Architecture).
|
||||
*
|
||||
* @return Whether you want to enable Concurrent Root for this surface or not.
|
||||
*/
|
||||
override fun isConcurrentRootEnabled(): Boolean {
|
||||
return concurrentRootEnabled
|
||||
}
|
||||
|
||||
override fun createRootView(): ReactRootView =
|
||||
ReactRootView(getContext()).apply { setIsFabric(fabricEnabled) }
|
||||
}
|
||||
@@ -12,6 +12,14 @@ import com.facebook.react.ReactNativeHost
|
||||
import com.facebook.react.ReactPackageTurboModuleManagerDelegate
|
||||
import com.facebook.react.bridge.JSIModulePackage
|
||||
|
||||
/**
|
||||
* A utility class that allows you to simplify the setup of a [ReactNativeHost] for new apps in Open
|
||||
* Source.
|
||||
*
|
||||
* Specifically, for apps that are using the New Architecture, this Default class takes care of
|
||||
* providing the default TurboModuleManagerDelegateBuilder and the default JSIModulePackage,
|
||||
* provided the name of the dynamic library to load.
|
||||
*/
|
||||
abstract class DefaultReactNativeHost protected constructor(application: Application) :
|
||||
ReactNativeHost(application) {
|
||||
|
||||
@@ -32,7 +40,7 @@ abstract class DefaultReactNativeHost protected constructor(application: Applica
|
||||
|
||||
/**
|
||||
* Returns the name of the dynamic library used by app on the New Architecture. This is generally
|
||||
* "<applicationname>_appmodules"
|
||||
* "<applicationname>_appmodules" or just "appmodules"
|
||||
*
|
||||
* If null, we will assume you're not using the New Architecture and will not attempt to load any
|
||||
* dynamic library at runtime.
|
||||
|
||||
Reference in New Issue
Block a user