diff --git a/packages/framer-motion/src/animation/legacy-popmotion/keyframes.ts b/packages/framer-motion/src/animation/legacy-popmotion/keyframes.ts index be2a8937b6..cb3d21b414 100644 --- a/packages/framer-motion/src/animation/legacy-popmotion/keyframes.ts +++ b/packages/framer-motion/src/animation/legacy-popmotion/keyframes.ts @@ -31,8 +31,6 @@ export function keyframes({ }: AnimationOptions): Animation { keyframeValues = [...keyframeValues] - const origin = keyframes[0] - /** * Easing functions can be externally defined as strings. Here we convert them * into actual functions. @@ -45,7 +43,10 @@ export function keyframes({ * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator * to reduce GC during animation. */ - const state: AnimationState = { done: false, value: origin } + const state: AnimationState = { + done: false, + value: keyframeValues[0], + } /** * Create a times array based on the provided 0-1 offsets @@ -53,7 +54,7 @@ export function keyframes({ const absoluteTimes = convertOffsetToTimes( // Only use the provided offsets if they're the correct length // TODO Maybe we should warn here if there's a length mismatch - times && times.length === keyframes.length + times && times.length === keyframeValues.length ? times : defaultOffset(keyframeValues), duration diff --git a/packages/framer-motion/src/motion/__tests__/transition-keyframes.test.tsx b/packages/framer-motion/src/motion/__tests__/transition-keyframes.test.tsx index ed06472234..11a008065c 100644 --- a/packages/framer-motion/src/motion/__tests__/transition-keyframes.test.tsx +++ b/packages/framer-motion/src/motion/__tests__/transition-keyframes.test.tsx @@ -114,4 +114,27 @@ describe("keyframes transition", () => { expect(xResult).toBe(50) }) + + test("times works as expected", async () => { + const values = await new Promise((resolve) => { + const output: number[] = [] + + const Component = () => ( + + output.push(Math.round(latest.x as number)) + } + onAnimationComplete={() => resolve(output)} + /> + ) + + const { rerender } = render() + rerender() + }) + + expect(values[0] >= 100).toBe(true) + expect(values[values.length - 2] <= 200).toBe(true) + }) })