Skip to content
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

Merged
merged 45 commits into from
Mar 10, 2023
Merged

Make animate() resolve for time #1993

merged 45 commits into from
Mar 10, 2023

Conversation

mattgperry
Copy link
Collaborator

@mattgperry mattgperry commented Mar 3, 2023

This PR replaces the animate function from the previous Popmotion approach which consumes time delta per frame (helpfully illustrated by this):

Screenshot 2023-03-08 at 08 57 37

Into the Motion One stateless approach where the timestamp itself is passed.

This allows for:

  • Playback functions. Currently we only return stop but for arbitrary seeking, pause, play of springs/inertia this stateless approach works better.
  • API parity with WAAPI. In a future PR this will allow animate to easily return a set of playback controls that wraps many JS and/or WAAPI animation controls.
  • Quicker seeking. Currently we have to simulate a low-res version of animations when sampling to ensure repeats are incorporated correctly whereas now this can be instant, which leads to faster optimised appear animation handoff and faster WAAPI interruption.

@mattgperry mattgperry changed the base branch from main to feature/for-t March 3, 2023 14:29
@mattgperry mattgperry force-pushed the feature/for-t branch 3 times, most recently from 2a5c454 to 643ade9 Compare March 7, 2023 14:46
@mergetron mergetron bot changed the base branch from feature/for-t to main March 7, 2023 14:49
@@ -103,10 +103,6 @@
"path": "./dist/size-rollup-animate.js",
"maxSize": "10 kB"
},
{
Copy link
Collaborator Author

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

elapsed,
delay: -elapsed,
Copy link
Contributor

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.

Copy link
Collaborator Author

@mattgperry mattgperry Mar 8, 2023

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.

Copy link
Contributor

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 😅

Copy link
Contributor

@nvh nvh left a 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.

@mattgperry mattgperry requested a review from nvh March 9, 2023 11:49
Copy link
Contributor

@nvh nvh left a 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.

Comment on lines +7 to +9
this.animations = animations.filter(
Boolean
) as AnimationPlaybackControls[]
Copy link
Contributor

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?

Copy link
Collaborator Author

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)

Comment on lines +12 to +14
get currentTime() {
return this.animations[0].currentTime
}
Copy link
Contributor

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?

Copy link
Collaborator Author

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])
Copy link
Contributor

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.

Comment on lines 49 to 48
? defaultTimestep
? 16.666
Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me - done

@mattgperry mattgperry added the automerge Land this PR label Mar 10, 2023
@mergetron mergetron bot merged commit f253ab6 into main Mar 10, 2023
@mergetron mergetron bot deleted the feature/for-t-2 branch March 10, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Land this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants