Skip to content

Commit

Permalink
Latest
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed May 16, 2024
1 parent 7481877 commit 736a47d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/framer-motion/src/value/use-spring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,42 @@ export function useSpring(

useInsertionEffect(() => {
let latestValue: number
let set: (v: number) => void
let latestSet: (v: number) => void

const startAnimation = () => {
/**
* If the previous animation hasn't had the chance to even render a frame, render it now.
*/
const animation = activeSpringAnimation.current

if (animation && animation.time === 0) {
animation.sample(frameData.delta)
}

stopAnimation()

console.log("useSpring", value.getVelocity(), frameData.currentStep)

activeSpringAnimation.current = animateValue({
keyframes: [value.get(), latestValue],
velocity: value.getVelocity(),
type: "spring",
restDelta: 0.001,
restSpeed: 0.01,
...config,
onUpdate: set,
onUpdate: latestSet,
})
}

return value.attach((v, frameSet) => {
return value.attach((v, set) => {
/**
* A more hollistic approach to this might be to use isStatic to fix VisualElement animations
* at that level, but this will work for now
*/
if (isStatic) return set(v)

latestValue = v
set = frameSet
latestSet = set

frame.update(startAnimation, true)
frame.update(startAnimation)

return value.get()
}, stopAnimation)
Expand Down

0 comments on commit 736a47d

Please sign in to comment.