Skip to content

Commit b3e8c0f

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Flush animation queue directly in useAnimatedProps
Summary: changelog: [internal] Call flushQueue directly from useAnimatedProps to avoid mismatch between `NativeAnimatedHelper.API.setWaitingForIdentifier` and `NativeAnimatedHelper.API.unsetWaitingForIdentifier` Previously, animation queue only got called if every `setWaitingForIdentifier` call was matched by `unsetWaitingForIdentifier`. If an error is thrown, this is not the case and they get out of sync. WHen they get out of sync, they never recover and animation queue is never flushedddddd. Reviewed By: yungsters Differential Revision: D38938858 fbshipit-source-id: c38fdef05cc70ce274b8e16114ffe49cc2dcb9b3
1 parent 3bae268 commit b3e8c0f

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Libraries/Animated/useAnimatedProps.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
useMemo,
2222
useReducer,
2323
useRef,
24-
useState,
2524
} from 'react';
2625

2726
type ReducedProps<TProps> = {
@@ -31,8 +30,6 @@ type ReducedProps<TProps> = {
3130
};
3231
type CallbackRef<T> = T => mixed;
3332

34-
let animatedComponentNextId = 1;
35-
3633
export default function useAnimatedProps<TProps: {...}, TInstance>(
3734
props: TProps,
3835
): [ReducedProps<TProps>, CallbackRef<TInstance | null>] {
@@ -141,16 +138,11 @@ function useAnimatedPropsLifecycle(node: AnimatedProps): void {
141138
const prevNodeRef = useRef<?AnimatedProps>(null);
142139
const isUnmountingRef = useRef<boolean>(false);
143140

144-
const [animatedComponentId] = useState(
145-
() => `${animatedComponentNextId++}:animatedComponent`,
146-
);
147-
148-
useLayoutEffect(() => {
149-
NativeAnimatedHelper.API.setWaitingForIdentifier(animatedComponentId);
150-
});
151-
152141
useEffect(() => {
153-
NativeAnimatedHelper.API.unsetWaitingForIdentifier(animatedComponentId);
142+
// It is ok for multiple components to call `flushQueue` because it noops
143+
// if the queue is empty. When multiple animated components are mounted at
144+
// the same time. Only first component flushes the queue and the others will noop.
145+
NativeAnimatedHelper.API.flushQueue();
154146
});
155147

156148
useLayoutEffect(() => {

0 commit comments

Comments
 (0)