Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN: Enable scheduleAnimatedEndCallbackInMicrotask #47503

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,23 @@ 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', () => {
it('triggers callback when spring is at rest', async () => {
const anim = new Animated.Value(0);
const callback = jest.fn();
Animated.spring(anim, {
toValue: 0,
velocity: 0,
useNativeDriver: false,
}).start(callback);
expect(callback).toBeCalled();

expect(callback).not.toBeCalled();
await jest.runOnlyPendingTimersAsync();
expect(callback).toBeCalledWith({finished: true});
});

it('send toValue when a critically damped spring stops', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ export default class Animation {
const callback = this.#onEnd;
if (callback != null) {
this.#onEnd = null;
if (ReactNativeFeatureFlags.scheduleAnimatedEndCallbackInMicrotask()) {
queueMicrotask(() => callback(result));
} else {
callback(result);
}
queueMicrotask(() => callback(result));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,11 @@ const definitions: FeatureFlagDefinitions = {
},
},
enableAnimatedAllowlist: {
defaultValue: false,
defaultValue: true,
metadata: {
dateAdded: '2024-09-10',
description:
'Enables Animated to skip non-allowlisted props and styles.',
purpose: 'experimentation',
purpose: 'release',
},
},
enableAnimatedClearImmediateFix: {
Expand All @@ -537,12 +536,11 @@ const definitions: FeatureFlagDefinitions = {
},
},
enableAnimatedPropsMemo: {
defaultValue: false,
defaultValue: true,
metadata: {
dateAdded: '2024-09-11',
description:
'Enables Animated to analyze props to minimize invalidating `AnimatedProps`.',
purpose: 'experimentation',
purpose: 'release',
},
},
enableOptimisedVirtualizedCells: {
Expand All @@ -562,15 +560,6 @@ const definitions: FeatureFlagDefinitions = {
purpose: 'release',
},
},
scheduleAnimatedEndCallbackInMicrotask: {
defaultValue: false,
metadata: {
dateAdded: '2024-09-27',
description:
'Changes the completion callback supplied via `Animation#start` to be scheduled in a microtask instead of synchronously executed.',
purpose: 'experimentation',
},
},
shouldSkipStateUpdatesForLoopingAnimations: {
defaultValue: false,
metadata: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<141c9d17083660b8726d2780813168dd>>
* @generated SignedSource<<716c4507093099c254b57d744366bd05>>
* @flow strict
*/

Expand Down Expand Up @@ -37,7 +37,6 @@ export type ReactNativeFeatureFlagsJsOnly = {
enableAnimatedPropsMemo: Getter<boolean>,
enableOptimisedVirtualizedCells: Getter<boolean>,
isLayoutAnimationEnabled: Getter<boolean>,
scheduleAnimatedEndCallbackInMicrotask: Getter<boolean>,
shouldSkipStateUpdatesForLoopingAnimations: Getter<boolean>,
shouldUseAnimatedObjectForTransform: Getter<boolean>,
shouldUseRemoveClippedSubviewsAsDefaultOnIOS: Getter<boolean>,
Expand Down Expand Up @@ -132,7 +131,7 @@ export const enableAccessToHostTreeInFabric: Getter<boolean> = createJavaScriptF
/**
* Enables Animated to skip non-allowlisted props and styles.
*/
export const enableAnimatedAllowlist: Getter<boolean> = createJavaScriptFlagGetter('enableAnimatedAllowlist', false);
export const enableAnimatedAllowlist: Getter<boolean> = createJavaScriptFlagGetter('enableAnimatedAllowlist', true);

/**
* Enables an experimental to use the proper clearIntermediate instead of calling the wrong clearTimeout and canceling another timer.
Expand All @@ -142,7 +141,7 @@ export const enableAnimatedClearImmediateFix: Getter<boolean> = createJavaScript
/**
* Enables Animated to analyze props to minimize invalidating `AnimatedProps`.
*/
export const enableAnimatedPropsMemo: Getter<boolean> = createJavaScriptFlagGetter('enableAnimatedPropsMemo', false);
export const enableAnimatedPropsMemo: Getter<boolean> = createJavaScriptFlagGetter('enableAnimatedPropsMemo', true);

/**
* Removing unnecessary rerenders Virtualized cells after any rerenders of Virualized list. Works with strict=true option
Expand All @@ -154,11 +153,6 @@ export const enableOptimisedVirtualizedCells: Getter<boolean> = createJavaScript
*/
export const isLayoutAnimationEnabled: Getter<boolean> = createJavaScriptFlagGetter('isLayoutAnimationEnabled', true);

/**
* Changes the completion callback supplied via `Animation#start` to be scheduled in a microtask instead of synchronously executed.
*/
export const scheduleAnimatedEndCallbackInMicrotask: Getter<boolean> = createJavaScriptFlagGetter('scheduleAnimatedEndCallbackInMicrotask', false);

/**
* If the animation is within Animated.loop, we do not send state updates to React.
*/
Expand Down
Loading