-
Notifications
You must be signed in to change notification settings - Fork 744
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
Make animate()
resolve for time
#1993
Conversation
b0df3b0
to
e5ac1e1
Compare
2a56ecb
to
f3fedd4
Compare
2a5c454
to
643ade9
Compare
f3fedd4
to
a1813ed
Compare
@@ -103,10 +103,6 @@ | |||
"path": "./dist/size-rollup-animate.js", | |||
"maxSize": "10 kB" | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dupe of previous size check
packages/framer-motion/src/animation/waapi/create-accelerated-animation.ts
Outdated
Show resolved
Hide resolved
packages/framer-motion/src/animation/generators/utils/velocity-sample-duration.ts
Outdated
Show resolved
Hide resolved
packages/framer-motion/src/animation/generators/spring/index.ts
Outdated
Show resolved
Hide resolved
elapsed, | ||
delay: -elapsed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really get this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous animate
accepted elapsed
. A negative elapsed
would effectively be a delay. The new animate
accepts delay
- a negative delay
is effectively an elapsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense yeah, maybe we could add this as a comment, for future me who will forget about it again 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some questions, and there are still some .only(
tests sprinkled here and there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, still have my doubts about the GroupedAnimationControl, but as it is obviously in flux I'll leave it up to you to fix now or later.
this.animations = animations.filter( | ||
Boolean | ||
) as AnimationPlaybackControls[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still so disappointed that typescript can't figure this out 😞
Is there no way to go without the cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually didn't even work with a more explicit function either (that checked specficially for undefined)
get currentTime() { | ||
return this.animations[0].currentTime | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be the max()
of currentTimes or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be correct for duration
, as I realised after implementing max
originally too. In theory all these animations should be in sync, some could be interrupted at which point this is a bit of a fudge, we probably want to filter out animations that aren't running or paused and take the duration from the first one of those. But I do want to take a second look at currentTime
before making an official API, this is just for internal use and it doesn't currently represent more than one animation, but I'll add a comment
return { | ||
stop: () => value.stop(), | ||
} | ||
return value.animation || new GroupPlaybackControls([value.animation]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we add the animation if it is falsy? I'd say we either always return a GroupPlaybackControls, or return an empty one when the animation doesn't exist.
? defaultTimestep | ||
? 16.666 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not making this a constant? I'd say that 1000/60 is clearer than this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Don't feel strongly though, as it is kinda common knowledge)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me - done
This PR replaces the
animate
function from the previous Popmotion approach which consumes time delta per frame (helpfully illustrated by this):Into the Motion One stateless approach where the timestamp itself is passed.
This allows for:
stop
but for arbitrary seeking, pause, play of springs/inertia this stateless approach works better.animate
to easily return a set of playback controls that wraps many JS and/or WAAPI animation controls.