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

Animation: Add interpolation functions #128

Closed
bryphe opened this issue Dec 20, 2018 · 6 comments
Closed

Animation: Add interpolation functions #128

bryphe opened this issue Dec 20, 2018 · 6 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@bryphe
Copy link
Member

bryphe commented Dec 20, 2018

Issue: Today, all our animation infrastructure uses a 'linear' easing function.

This happens in our getLocalTime method - we're implicitly using the linear easing function which is just t => t. However, linear easing is not very visually appealing - usually you want an easing style animation which more closely replicates a physical model.

The proposal is to add an additional parameter, easing to our animation options:
https://github.com/bryphe/revery/blob/e024382f2631ac2026f129c52091e410c5e7a29a/src/UI/Animation.re#L27

This would be simply a function of type easingFunction: float => float.

The user could define their own easing function, or we could have some defaults:

  • linear
  • step(boundary) would be t => t < boundary ? : 0.0 : 1.0
  • quadratic would be t => t * t
  • cubic would be t => t * t * t
  • easeIn
  • easeOut
  • easeInOut
@bryphe
Copy link
Member Author

bryphe commented Dec 20, 2018

This would be useful for #121 as well

@bryphe bryphe added help wanted Extra attention is needed good first issue Good for newcomers labels Dec 20, 2018
@Bretley
Copy link
Contributor

Bretley commented Dec 21, 2018

@bryphe I added the type for easing into the record and defined linear, quadratic, and cubic. What part of Animation.re needs to be changed so that we use easing instead of default linear

@bryphe
Copy link
Member Author

bryphe commented Dec 22, 2018

@Bretley - awesome! Would you mind posting up a PR of what you have so far? I can help point out the place we need to change to integrate the new easing functions

@albertorestifo
Copy link

@Bretley are you still working on this?

@jchavarri
Copy link
Member

@Bretley @albertorestifo A PR for "scroll bouncing" landed yesterday that added some missing easing functions to Animation.re:

let cubicBezier = Rebez.make;
// From https://developer.mozilla.org/en-US/docs/Web/CSS/timing-function#Keywords_for_common_cubic-bezier_timing_functions
let ease = cubicBezier(0.25, 0.1, 0.25, 1.0);
let easeIn = cubicBezier(0.42, 0.0, 1.0, 1.0);
let easeOut = cubicBezier(0.0, 0.0, 0.58, 1.0);
let easeInOut = cubicBezier(0.42, 0.0, 0.58, 1.0);

The actual calculation of the values was put into a separate repo, at least temporarily, just because it could be useful for other folks (and I needed at some point a "clean slate" to properly test it, think about it, and understand what was going on with some nasty bugs 😅 ): https://github.com/jchavarri/rebez.

There is some functionality to tween and also "chain" different animations, that can be seen in the tests.

Sorry about that, I didn't realize there was an issue about easing.


Having said so, I think the Animation module could still benefit from exposing spring-based animations as well. I've been looking at react-spring and popmotion for inspiration, but if anyone wants to take over and investigate that, it'd be awesome 🙂

@bryphe Not sure if the spring animations work would deserve a new issue though? as this one was explicitly targeting easing functions.

@bryphe
Copy link
Member Author

bryphe commented Feb 13, 2019

@jchavarri - amazing work! Thanks for implementing the remainder of easing functions.

@bryphe Not sure if the spring animations work would deserve a new issue though? as this one was explicitly targeting easing functions.

I would love to have spring-based motion (some of those demos are really impressive for react-spring / popmotion - especially how little code it takes to get nice effects).

I did log an issue previously in #131 - but it might be a bit too opionionated (maybe useSpring is wrong and there is a better API) - but we could start tracking discussion there, and rename it if needed? react-spring and popmotion might expose a more battle-tested and usable API.

In the meantime, sounds like the work here is done between #149 and #315 , so we can close this one out 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants