jtrivedi / Wave

Wave is a spring-based animation engine for iOS and macOS that makes it easy to create fluid, interruptible animations that feel great.
https://jtrivedi.github.io/Wave/
MIT License
2.04k stars 55 forks source link

Allow an animation not to require an explicit restart after the target is reached then updated again. #13

Open Clafou opened 2 years ago

Clafou commented 2 years ago

This framework is great and I found it easy to replace Facebook pop – thank you!

One minor issue I have is that animations automatically stop when the target value is reached, then become inactive. Any further change to the target value is ignored until the animation is explicitly restarted. But an app may not care whether the animation has reached its target and may just want to animate changes by updating the target.

Facebook pop has a removedOnCompletion property to address this and keep animations alive when set to false. Would it be possible to add something similar?

jtrivedi commented 2 years ago

Hey @Clafou, I'm glad to hear you're enjoying Wave!

To confirm, the idea you're proposing is that with this flag enabled, any time a property animation's target is changed, it would automatically start, correct? Or is it that the animation would actually continually run, independent of the the current value?

I'm open to this, but would like to understand the benefits/use-case more. It seems that it would just eliminate a call to start, which doesn't seem like a large benefit?

Clafou commented 2 years ago

Hi Janum, thanks for the response.

Yes, my suggestion is to make it possible to change target without calling start again. Basically it's about keeping an animation alive rather than allow it to become inactive automatically. It doesn't need to continually run when its target is reached but it needs to resume animating if the target changes again at a later point, until explicitly stopped.

For example, say you have an animation that depends on a scrollview's offset, which the end user controls by swiping. For the client code it makes sense to create a property animation, start it, and simply update target when the scroll offset changes. But because the animation automatically becomes inactive if it ever reaches its target, the client needs to call start each time after (or before?) it updates target, since it doesn't know (or care) if the animation is still active. I can see in the current implementation that there is no cost involved in calling start repeatedly, so there is no problem as long as this remains the case. But for such a property animation my expectation would be to call start only once at initialisation time and then just update target without having to consider the current state of the animation, at least until I call stop or until the animation object deinits.

jtrivedi commented 2 years ago

Hey @Clafou! Sorry for the delay here -- I agree with this proposal and will post a patch soon.