tabris-js
tabris-js copied to clipboard
Cancel functionality for Widget animate method
It will be great if you can add a cancel functionality for the widget animate method. It will be very helpful if we want to stop an infinite animation by example
Considering there is already internal api doing this it's only a question of how the public API would look like. I don't see any good way to integrate it in to the animate()
method. So we can either make the internal Animation
class public, or we can add a utility function like this:
cancelAnimation(widget)
.
Any thoughts @mpost?
Note to self: animate
could also return an object with a cancel
method that is an instance of a subclass of Promise
so there is no breaking change but it's still convinient to tuse.
There are ambiguites with canceling animations:
- Should the promise still reject as it does when the widget is disposed? (current behavior: yes)
- What values should the animated properties contain? (current behavior: as though animation completed)
- What visual state should the widget stay in? (current behavior: unknown)
Note that here is currently no way for the animated properties to represent the visual state of an incomplete animation.
Should the promise still reject as it does when the widget is disposed? (current behavior: yes)
I would be in favor of resolving with a status instead of rejecting when the widget is disposed during a running animation or when the animation is manually aborted, since this is not exceptional behavior but is rather common.
E.g.:
... onSelect={() => componentChild.animate()} ...
... is a common pattern that would result into a console.error
log due to an unhandled promise rejection in an event callback when componentChild
(or often, its parent component) is disposed before the componentChild
animation is finished.