From 907b9d5dd3e0d2365416640581ab7fa19e7f1b91 Mon Sep 17 00:00:00 2001 From: Zeya Peng Date: Tue, 16 Jun 2026 06:23:31 -0700 Subject: [PATCH] Flip cxxNativeAnimatedEnabled featureflag default to true (#57204) Summary: ## Changelog: [General] [Changed] - Flip cxxNativeAnimatedEnabled featureflag default to true Reviewed By: javache Differential Revision: D108323433 --- .../ReactNativeFeatureFlagsDefaults.kt | 4 +-- .../ReactNativeFeatureFlagsDefaults.h | 4 +-- .../ReactNativeFeatureFlags.config.js | 2 +- .../private/animated/NativeAnimatedHelper.js | 25 +++++++++++++------ .../featureflags/ReactNativeFeatureFlags.js | 4 +-- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index 818eb338551d..4ac77546a85d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -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<<061d668cf04041f4d3d2f48f11dc739f>> + * @generated SignedSource<<5f6861a5aa2d6024ad8d4c236652bf64>> */ /** @@ -27,7 +27,7 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun cdpInteractionMetricsEnabled(): Boolean = false - override fun cxxNativeAnimatedEnabled(): Boolean = false + override fun cxxNativeAnimatedEnabled(): Boolean = true override fun defaultTextToOverflowHidden(): Boolean = true diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index e0bebd010bc9..9c404b1453fa 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -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<<8dfc52502bd539e5e43d547f895a6d33>> + * @generated SignedSource<> */ /** @@ -36,7 +36,7 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { } bool cxxNativeAnimatedEnabled() override { - return false; + return true; } bool defaultTextToOverflowHidden() override { diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index 15976d671629..52da0a057444 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -72,7 +72,7 @@ const definitions: FeatureFlagDefinitions = { ossReleaseStage: 'none', }, cxxNativeAnimatedEnabled: { - defaultValue: false, + defaultValue: true, metadata: { dateAdded: '2025-03-14', description: diff --git a/packages/react-native/src/private/animated/NativeAnimatedHelper.js b/packages/react-native/src/private/animated/NativeAnimatedHelper.js index f27650b3d327..9afd64374e5c 100644 --- a/packages/react-native/src/private/animated/NativeAnimatedHelper.js +++ b/packages/react-native/src/private/animated/NativeAnimatedHelper.js @@ -71,6 +71,21 @@ let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null; const shouldSignalBatch: boolean = ReactNativeFeatureFlags.cxxNativeAnimatedEnabled(); +// Schedules `API.flushQueue` after the current batch, replacing any pending +// flush. On device `setImmediate` is a microtask; under jest's fake timers it's +// a fake-timer entry that only `runAllTimers` drains — not `await` or +// `advanceTimersByTime` — so the deferred flush wouldn't run before a test's +// assertions. Flush synchronously in tests instead. +function scheduleQueueFlush(): void { + clearImmediate(flushQueueImmediate); + if (process.env.NODE_ENV === 'test') { + // TODO: T275950736 - remove this path + API.flushQueue(); + } else { + flushQueueImmediate = setImmediate(API.flushQueue); + } +} + function createNativeOperations(): NonNullable { const methodNames = [ 'createAnimatedNode', // 1 @@ -116,8 +131,7 @@ function createNativeOperations(): NonNullable { // details, see `NativeAnimatedModule.queueAndExecuteBatchedOperations`. singleOpQueue.push(operationID, ...args); if (shouldSignalBatch) { - clearImmediate(flushQueueImmediate); - flushQueueImmediate = setImmediate(API.flushQueue); + scheduleQueueFlush(); } }; } @@ -137,8 +151,7 @@ function createNativeOperations(): NonNullable { } else if (shouldSignalBatch) { // $FlowExpectedError[incompatible-call] - Dynamism. queue.push(() => method(...args)); - clearImmediate(flushQueueImmediate); - flushQueueImmediate = setImmediate(API.flushQueue); + scheduleQueueFlush(); } else { // $FlowExpectedError[incompatible-call] - Dynamism. method(...args); @@ -190,9 +203,7 @@ const API = { invariant(NativeAnimatedModule, 'Native animated module is not available'); if (ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush()) { - const prevImmediate = flushQueueImmediate; - clearImmediate(prevImmediate); - flushQueueImmediate = setImmediate(API.flushQueue); + scheduleQueueFlush(); } else { API.flushQueue(); } diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 403f339511aa..fee4c4c52e6a 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -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<<609451fd0a38e0f8eaf685e7cf534e27>> + * @generated SignedSource<<1de542d9c189f934f52fc258fd591b06>> * @flow strict * @noformat */ @@ -224,7 +224,7 @@ export const cdpInteractionMetricsEnabled: Getter = createNativeFlagGet /** * Use a C++ implementation of Native Animated instead of the platform implementation. */ -export const cxxNativeAnimatedEnabled: Getter = createNativeFlagGetter('cxxNativeAnimatedEnabled', false); +export const cxxNativeAnimatedEnabled: Getter = createNativeFlagGetter('cxxNativeAnimatedEnabled', true); /** * When enabled, sets the default overflow style for Text components to hidden instead of visible. */