From 8793b7d89bcafdfcca7ecb953e60882b67ffc807 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 6 Dec 2024 12:05:46 -0800 Subject: [PATCH] RN: Backout "Scheduling Animated End Callbacks in Microtask" (#48132) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48132 Backs out D63573322 and D65645981, reverting the change that makes callbacks passed to `animation.start()` scheduled for execution in a microtask. This is being reverted becuase the latency introduced by the current macro and pending micro tasks can introduce visible latency artifacts that diminish the fidelity of animations. Changelog: [General][Changed] - Reverts #47503. (~~Callbacks passed to `animation.start()` will be scheduled for execution in a microtask. Previously, there were certain scenarios in which the callback could be synchronously executed by `start`.~~) Reviewed By: javache Differential Revision: D66852804 fbshipit-source-id: 08434b9876813fe9e8b189b6b467198933843bf0 --- .../Libraries/Animated/__tests__/Animated-test.js | 9 ++------- .../Libraries/Animated/animations/Animation.js | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/react-native/Libraries/Animated/__tests__/Animated-test.js b/packages/react-native/Libraries/Animated/__tests__/Animated-test.js index fde378c260b..ba471e03a12 100644 --- a/packages/react-native/Libraries/Animated/__tests__/Animated-test.js +++ b/packages/react-native/Libraries/Animated/__tests__/Animated-test.js @@ -121,12 +121,10 @@ describe('Animated', () => { await unmount(root); - expect(callback).not.toBeCalled(); - await jest.runOnlyPendingTimersAsync(); expect(callback).toBeCalledWith({finished: false}); }); - it('triggers callback when spring is at rest', async () => { + it('triggers callback when spring is at rest', () => { const anim = new Animated.Value(0); const callback = jest.fn(); Animated.spring(anim, { @@ -134,10 +132,7 @@ describe('Animated', () => { velocity: 0, useNativeDriver: false, }).start(callback); - - expect(callback).not.toBeCalled(); - await jest.runOnlyPendingTimersAsync(); - expect(callback).toBeCalledWith({finished: true}); + expect(callback).toBeCalled(); }); it('send toValue when a critically damped spring stops', () => { diff --git a/packages/react-native/Libraries/Animated/animations/Animation.js b/packages/react-native/Libraries/Animated/animations/Animation.js index c4fb8faac79..5662a7903a3 100644 --- a/packages/react-native/Libraries/Animated/animations/Animation.js +++ b/packages/react-native/Libraries/Animated/animations/Animation.js @@ -170,7 +170,7 @@ export default class Animation { const callback = this.#onEnd; if (callback != null) { this.#onEnd = null; - queueMicrotask(() => callback(result)); + callback(result); } } }