Do not flush Animated operation queue on mount for some feature flags (#51461)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51461

We are trying to minimize the amount of non-determinism in flushing Animated operation queues. Initially the `ReactNativeFeatureFlags.animatedShouldSignalBatch` handled non-determinism on the native side, eliminating the use of native mount hooks to trigger operation batch flushes in the native module. However, there is additional non-determinism introduced by JS, where the set of pending Animated operations may be flushed as a result of an effect.

This change eliminates the flushing of Animated operations in the `useEffect` for `createAnimatedPropsHook.js`.

## Changelog

[Internal]

Reviewed By: yungsters, zeyap

Differential Revision: D75003751

fbshipit-source-id: 73c7bb02355b5f634f4a800f46ca5f529cd15ebd
This commit is contained in:
Eric Rozell authored and Facebook GitHub Bot committed 2025-05-19 13:49:27 -07:00
1 parent 71caf2c557
commit 2f761ee7c4
2 files changed
+9 -4

No files matched your search

@@ -57,7 +57,7 @@ const eventListenerAnimationFinishedCallbacks: {
let globalEventEmitterGetValueListener: ?EventSubscription = null;
let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null;
const shouldSignalBatch =
const shouldSignalBatch: boolean =
ReactNativeFeatureFlags.animatedShouldSignalBatch() ||
ReactNativeFeatureFlags.cxxNativeAnimatedEnabled();
@@ -440,6 +440,7 @@ export default {
generateNewAnimationId,
assertNativeAnimatedModule,
shouldUseNativeDriver,
shouldSignalBatch,
transformDataType,
// $FlowExpectedError[unsafe-getters-setters] - unsafe getter lint suppression
// $FlowExpectedError[missing-type-arg] - unsafe getter lint suppression
@@ -66,9 +66,13 @@ export default function createAnimatedPropsHook(
);
useEffect(() => {
// If multiple components call `flushQueue`, the first one will flush the
// queue and subsequent ones will do nothing.
NativeAnimatedHelper.API.flushQueue();
// Animated queue flush is handled deterministically in setImmediate for the following feature flags:
// animatedShouldSignalBatch, cxxNativeAnimatedEnabled
if (!NativeAnimatedHelper.shouldSignalBatch) {
// If multiple components call `flushQueue`, the first one will flush the
// queue and subsequent ones will do nothing.
NativeAnimatedHelper.API.flushQueue();
}
let drivenAnimationEndedListener: ?EventSubscription = null;
if (node.__isNative) {
drivenAnimationEndedListener =