Skip to content

Commit 2f761ee

Browse files
rozelefacebook-github-bot
authored andcommitted
Do not flush Animated operation queue on mount for some feature flags (#51461)
Summary: Pull Request resolved: #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
1 parent 71caf2c commit 2f761ee

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/react-native/src/private/animated/NativeAnimatedHelper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const eventListenerAnimationFinishedCallbacks: {
5757
let globalEventEmitterGetValueListener: ?EventSubscription = null;
5858
let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null;
5959

60-
const shouldSignalBatch =
60+
const shouldSignalBatch: boolean =
6161
ReactNativeFeatureFlags.animatedShouldSignalBatch() ||
6262
ReactNativeFeatureFlags.cxxNativeAnimatedEnabled();
6363

@@ -440,6 +440,7 @@ export default {
440440
generateNewAnimationId,
441441
assertNativeAnimatedModule,
442442
shouldUseNativeDriver,
443+
shouldSignalBatch,
443444
transformDataType,
444445
// $FlowExpectedError[unsafe-getters-setters] - unsafe getter lint suppression
445446
// $FlowExpectedError[missing-type-arg] - unsafe getter lint suppression

packages/react-native/src/private/animated/createAnimatedPropsHook.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ export default function createAnimatedPropsHook(
6666
);
6767

6868
useEffect(() => {
69-
// If multiple components call `flushQueue`, the first one will flush the
70-
// queue and subsequent ones will do nothing.
71-
NativeAnimatedHelper.API.flushQueue();
69+
// Animated queue flush is handled deterministically in setImmediate for the following feature flags:
70+
// animatedShouldSignalBatch, cxxNativeAnimatedEnabled
71+
if (!NativeAnimatedHelper.shouldSignalBatch) {
72+
// If multiple components call `flushQueue`, the first one will flush the
73+
// queue and subsequent ones will do nothing.
74+
NativeAnimatedHelper.API.flushQueue();
75+
}
7276
let drivenAnimationEndedListener: ?EventSubscription = null;
7377
if (node.__isNative) {
7478
drivenAnimationEndedListener =

0 commit comments

Comments
 (0)