Skip to content

Commit

Permalink
Migrate enableEagerRootViewAttachment to ReactNativeFeatureFlags (#45604
Browse files Browse the repository at this point in the history
)

Summary:
Pull Request resolved: #45604

Migrate enableEagerRootViewAttachment to ReactNativeFeatureFlags

changelog: [internal] internal

Reviewed By: NickGerleman

Differential Revision: D60022934

fbshipit-source-id: 1a1c3a030d8673dd13c7c87091210dfe8fe5a089
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jul 28, 2024
1 parent 5386ece commit 34fb23b
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 52 deletions.
1 change: 0 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
public static field dispatchPointerEvents Z
public static field enableBridgelessArchitecture Z
public static field enableCppPropsIteratorSetter Z
public static field enableEagerRootViewAttachment Z
public static field enableFabricLogs Z
public static field enableFabricRenderer Z
public static field enableViewRecycling Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.modules.appregistry.AppRegistry;
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
import com.facebook.react.uimanager.DisplayMetricsHolder;
Expand Down Expand Up @@ -478,7 +479,7 @@ public void startReactApplication(
mReactInstanceManager.createReactContextInBackground();
// if in this experiment, we initialize the root earlier in startReactApplication
// instead of waiting for the initial measure
if (ReactFeatureFlags.enableEagerRootViewAttachment) {
if (ReactNativeFeatureFlags.enableEagerRootViewAttachment()) {
if (!mWasMeasured) {
// Ideally, those values will be used by default, but we only update them here to scope
// this change to `enableEagerRootViewAttachment` experiment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public class ReactFeatureFlags {
/** This feature flag enables logs for Fabric */
public static boolean enableFabricLogs = false;

/** Feature flag to configure eager attachment of the root view/initialisation of the JS code */
public static boolean enableEagerRootViewAttachment = false;

public static boolean dispatchPointerEvents = false;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ca939ab47fa68fbb5acf5ea34481def9>>
* @generated SignedSource<<fe2b592db8339808bf8ab727594ec6e0>>
*/

/**
Expand Down Expand Up @@ -82,6 +82,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableCleanTextInputYogaNode(): Boolean = accessor.enableCleanTextInputYogaNode()

/**
* Feature flag to configure eager attachment of the root view/initialisation of the JS code.
*/
@JvmStatic
public fun enableEagerRootViewAttachment(): Boolean = accessor.enableEagerRootViewAttachment()

/**
* When the app is completely migrated to Fabric, set this flag to true to disable parts of Paper infrastructure that are not needed anymore but consume memory and CPU. Specifically, UIViewOperationQueue and EventDispatcherImpl will no longer work as they will not subscribe to ReactChoreographer for updates.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2a8d5ca8a0ac46b4d3177cb8b12ad7ac>>
* @generated SignedSource<<0341c3c0f1eb484c305ee8732d6fd26f>>
*/

/**
Expand All @@ -29,6 +29,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var destroyFabricSurfacesInReactInstanceManagerCache: Boolean? = null
private var enableAlignItemsBaselineOnFabricIOSCache: Boolean? = null
private var enableCleanTextInputYogaNodeCache: Boolean? = null
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableLongTaskAPICache: Boolean? = null
Expand Down Expand Up @@ -139,6 +140,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun enableEagerRootViewAttachment(): Boolean {
var cached = enableEagerRootViewAttachmentCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableEagerRootViewAttachment()
enableEagerRootViewAttachmentCache = cached
}
return cached
}

override fun enableFabricRendererExclusively(): Boolean {
var cached = enableFabricRendererExclusivelyCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<aaf205098eaac9171aa15bc8f7bda805>>
* @generated SignedSource<<82a0b829cbc75d864dba1ae4c65b2036>>
*/

/**
Expand Down Expand Up @@ -46,6 +46,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableCleanTextInputYogaNode(): Boolean

@DoNotStrip @JvmStatic public external fun enableEagerRootViewAttachment(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricRendererExclusively(): Boolean

@DoNotStrip @JvmStatic public external fun enableGranularShadowTreeStateReconciliation(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fc363737bfe42515306043b836820f3f>>
* @generated SignedSource<<f028022c11b7dcfdfdd4fc8e3951aefe>>
*/

/**
Expand Down Expand Up @@ -41,6 +41,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableCleanTextInputYogaNode(): Boolean = false

override fun enableEagerRootViewAttachment(): Boolean = false

override fun enableFabricRendererExclusively(): Boolean = false

override fun enableGranularShadowTreeStateReconciliation(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<82f6d4eda4011bee81810af366f5d677>>
* @generated SignedSource<<833b024aec14737d59abd02092fcfa11>>
*/

/**
Expand Down Expand Up @@ -33,6 +33,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var destroyFabricSurfacesInReactInstanceManagerCache: Boolean? = null
private var enableAlignItemsBaselineOnFabricIOSCache: Boolean? = null
private var enableCleanTextInputYogaNodeCache: Boolean? = null
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableLongTaskAPICache: Boolean? = null
Expand Down Expand Up @@ -152,6 +153,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableEagerRootViewAttachment(): Boolean {
var cached = enableEagerRootViewAttachmentCache
if (cached == null) {
cached = currentProvider.enableEagerRootViewAttachment()
accessedFeatureFlags.add("enableEagerRootViewAttachment")
enableEagerRootViewAttachmentCache = cached
}
return cached
}

override fun enableFabricRendererExclusively(): Boolean {
var cached = enableFabricRendererExclusivelyCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ece587d5e6643fb906cfee816824f224>>
* @generated SignedSource<<69c396cad1d473c5793df517fa183f95>>
*/

/**
Expand Down Expand Up @@ -41,6 +41,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableCleanTextInputYogaNode(): Boolean

@DoNotStrip public fun enableEagerRootViewAttachment(): Boolean

@DoNotStrip public fun enableFabricRendererExclusively(): Boolean

@DoNotStrip public fun enableGranularShadowTreeStateReconciliation(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7c14f956fd20226acfb532d806c6eb7a>>
* @generated SignedSource<<e1a5c4bfa72b16c95464432e449b4ba8>>
*/

/**
Expand Down Expand Up @@ -93,6 +93,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool enableEagerRootViewAttachment() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableEagerRootViewAttachment");
return method(javaProvider_);
}

bool enableFabricRendererExclusively() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFabricRendererExclusively");
Expand Down Expand Up @@ -310,6 +316,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableCleanTextInputYogaNode(
return ReactNativeFeatureFlags::enableCleanTextInputYogaNode();
}

bool JReactNativeFeatureFlagsCxxInterop::enableEagerRootViewAttachment(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableEagerRootViewAttachment();
}

bool JReactNativeFeatureFlagsCxxInterop::enableFabricRendererExclusively(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableFabricRendererExclusively();
Expand Down Expand Up @@ -494,6 +505,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableCleanTextInputYogaNode",
JReactNativeFeatureFlagsCxxInterop::enableCleanTextInputYogaNode),
makeNativeMethod(
"enableEagerRootViewAttachment",
JReactNativeFeatureFlagsCxxInterop::enableEagerRootViewAttachment),
makeNativeMethod(
"enableFabricRendererExclusively",
JReactNativeFeatureFlagsCxxInterop::enableFabricRendererExclusively),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f06779455d65f78f561eaca745262a99>>
* @generated SignedSource<<1722d711f77b3f47cc3c665fce026b5a>>
*/

/**
Expand Down Expand Up @@ -57,6 +57,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableCleanTextInputYogaNode(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableEagerRootViewAttachment(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableFabricRendererExclusively(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.facebook.react.bridge.ReactTestHelper
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.WritableMap
import com.facebook.react.common.SystemClock
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
import com.facebook.react.uimanager.DisplayMetricsHolder
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.uimanager.events.Event
Expand Down Expand Up @@ -56,6 +57,8 @@ class RootViewTest {

@Before
fun setUp() {
ReactNativeFeatureFlagsForTests.setUp()

arguments = Mockito.mockStatic(Arguments::class.java)
arguments.`when`<WritableArray> { Arguments.createArray() }.thenAnswer { JavaOnlyArray() }
arguments.`when`<WritableMap> { Arguments.createMap() }.thenAnswer { JavaOnlyMap() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bab53ba585938b3bf458dbe0874931f8>>
* @generated SignedSource<<459682475d0fcefcdfce6ebeb7d1db19>>
*/

/**
Expand Down Expand Up @@ -57,6 +57,10 @@ bool ReactNativeFeatureFlags::enableCleanTextInputYogaNode() {
return getAccessor().enableCleanTextInputYogaNode();
}

bool ReactNativeFeatureFlags::enableEagerRootViewAttachment() {
return getAccessor().enableEagerRootViewAttachment();
}

bool ReactNativeFeatureFlags::enableFabricRendererExclusively() {
return getAccessor().enableFabricRendererExclusively();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<55d6c0f7ab8abe8411194235ab362cd2>>
* @generated SignedSource<<83a6879d27dd7dbcb181f30c3b6f0225>>
*/

/**
Expand Down Expand Up @@ -82,6 +82,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableCleanTextInputYogaNode();

/**
* Feature flag to configure eager attachment of the root view/initialisation of the JS code.
*/
RN_EXPORT static bool enableEagerRootViewAttachment();

/**
* When the app is completely migrated to Fabric, set this flag to true to disable parts of Paper infrastructure that are not needed anymore but consume memory and CPU. Specifically, UIViewOperationQueue and EventDispatcherImpl will no longer work as they will not subscribe to ReactChoreographer for updates.
*/
Expand Down
Loading

0 comments on commit 34fb23b

Please sign in to comment.