Files
react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactActivityDelegate.kt
T
Nicola Corti dd6d5a78a3 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
2022-08-18 07:30:23 -07:00

47 lines
1.6 KiB
Kotlin

/*
* 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) }
}