rive-flutter icon indicating copy to clipboard operation
rive-flutter copied to clipboard

LinearAnimationInstance unable to run one-shot more than once

Open BobaTrek opened this issue 2 years ago • 3 comments

Description

The class LinearAnimationInstance sets _didLoop to true after completing a one-shot animation. The class LinearAnimationInstance then returns false for keepGoing because of the following line of code: bool get keepGoing => animation.loop != Loop.oneShot || !_didLoop;

Consequently, after running the animation once, setting controller.isActive back to true does not re-run the animation. Perhaps this is intentional?

Workaround?

I found the following code will allow you to re-run the animation (scPulse is my SpeedController which uses LinearAnimationInstance:

scPulse.instance.reset(); scPulse.instance.advance(0); // This sets _didloop back to false as a side effect; scPulse.isActive = true;

Should _didloop be set to false as part of the reset() call (or when isActive gets set false) instead of relying on the side effect of calling advance(0)?

BobaTrek avatar May 20 '23 18:05 BobaTrek

Hi @BobaTrek have you taken a look at OneShotAnimation?

HayesGordon avatar May 22 '23 08:05 HayesGordon

Yes, I did use OneShotAnimation first, but I need to be able to change the speed of the animation as well, so I switched to the SpeedController mechanism. I am still thinking _didloop should be set to false in the LinearAnimationInstance.reset() function, but at least for now there is a workaround by calling .advance(0).

(Switching to SpeedController has presented a different problem, see #317)

BobaTrek avatar May 23 '23 15:05 BobaTrek

I'll take a deeper look into this soon.

HayesGordon avatar May 23 '23 16:05 HayesGordon

Closing this as it's something we won't change in the short-medium term, and in the long term this underlying Dart code will be replaced with a C++ counterpart and the API will look different.

HayesGordon avatar Aug 12 '24 14:08 HayesGordon