Skip to content

Commit 02e32c8

Browse files
committed
fix: Invalid web LA keyframe processing when from/to offset is used (#8035)
## Summary The previous implementation used an invalid type for the `KeyframeDefinitions` type assuming that all keys in `KeyframeDefinitions` are numbers. Because of that, it also converted all keys to numbers via the `.map(Number)` mapping which gave `NaN` offset values in the `offsets` array. As a result, the easing shift didn't work properly as `NaN` aren't valid offsets so we were getting `undefined` instead of the valid keyframe definition object. ## Example recordings ### Before https://github.com/user-attachments/assets/1dd8933c-1811-41c7-ada1-4a87c29404c3 ### After https://github.com/user-attachments/assets/7b62f9ad-8d29-4e0f-99e4-89faf2cc19c6
1 parent f37e10b commit 02e32c8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/react-native-reanimated/src/layoutReanimation/web/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ import type { AnimationData, AnimationStyle } from './animationParser';
4343

4444
export type AnimationCallback = ((finished: boolean) => void) | null;
4545

46-
export type KeyframeDefinitions = Record<number, AnimationStyle>;
46+
export type KeyframeDefinitions = Record<
47+
`${number}` | 'from' | 'to',
48+
AnimationStyle
49+
>;
4750

4851
export type InitialValuesStyleProps = Omit<StyleProps, 'opacity'> & {
4952
opacity?: number;

packages/react-native-reanimated/src/layoutReanimation/web/createAnimation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ export function createCustomKeyFrameAnimation(
7171
// Move keyframe easings one keyframe up (our LA Keyframe definition is different
7272
// from the CSS keyframes and expects easing to be present in the keyframe to which
7373
// we animate instead of the keyframe we animate from)
74-
const offsets = Object.keys(keyframeDefinitions).map(Number);
74+
const offsets = Object.keys(
75+
keyframeDefinitions
76+
) as (keyof KeyframeDefinitions)[];
7577

7678
for (let i = 1; i < offsets.length; i++) {
7779
const style = keyframeDefinitions[offsets[i]];
7880
if (style.easing) {
79-
keyframeDefinitions[i - 1].easing = style.easing;
81+
keyframeDefinitions[offsets[i - 1]].easing = style.easing;
8082
delete style.easing;
8183
}
8284
}

0 commit comments

Comments
 (0)