Skip to content

Commit bd69eea

Browse files
committed
Speeding up keyframe pregeneration
1 parent ec15b0c commit bd69eea

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

packages/framer-motion/src/animation/legacy-popmotion/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,21 @@ export function animateValue<V = number>({
195195
* animate() can't yet be sampled for time, instead it
196196
* consumes time. So to sample it we have to run a low
197197
* temporal-resolution version.
198+
*
199+
* isControlled should be set to true if sample is being run within
200+
* a loop. This indicates that we're not arbitrarily sampling
201+
* the animation but running it one step after another. Therefore
202+
* we don't need to run a low-res version here. This is a stop-gap
203+
* until a rewrite can sample for time.
198204
*/
199-
sample: (t: number) => {
205+
sample: (t: number, isControlled: boolean = false) => {
200206
elapsed = initialElapsed
207+
208+
if (isControlled) {
209+
update(t)
210+
return state
211+
}
212+
201213
const sampleResolution =
202214
duration && typeof duration === "number"
203215
? Math.max(duration * 0.5, 50)

packages/framer-motion/src/animation/waapi/create-accelerated-animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function createAcceleratedAnimation(
6969
*/
7070
let t = 0
7171
while (!state.done && t < 20000) {
72-
state = sampleAnimation.sample(t)
72+
state = sampleAnimation.sample(t, true)
7373
pregeneratedKeyframes.push(state.value)
7474
t += sampleDelta
7575
}

packages/framer-motion/src/frameloop/types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ export interface Step {
1717
process: (frame: FrameData) => void
1818
}
1919

20-
export type StepId =
21-
| "read"
22-
| "update"
23-
| "postUpdate"
24-
| "preRender"
25-
| "render"
26-
| "postRender"
20+
export type StepId = "read" | "update" | "preRender" | "render" | "postRender"
2721

2822
export type Sync = {
2923
[key in StepId]: Schedule

0 commit comments

Comments
 (0)