tabris-js icon indicating copy to clipboard operation
tabris-js copied to clipboard

Cancel functionality for Widget animate method

Open ishigo1987 opened this issue 3 years ago • 4 comments

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

ishigo1987 avatar Jan 27 '21 15:01 ishigo1987

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?

tbuschto avatar Apr 14 '21 12:04 tbuschto

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.

tbuschto avatar Jul 19 '21 08:07 tbuschto

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.

tbuschto avatar Jul 19 '21 09:07 tbuschto

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.

cpetrov avatar Jul 19 '21 09:07 cpetrov