mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-06-28 02:37:16 +08:00
Merge pull request #58 from rive-app/fix_28
Ensure last frame is applied
This commit is contained in:
@ -12,6 +12,7 @@ class SimpleAnimation extends RiveAnimationController<RuntimeArtboard> {
|
|||||||
|
|
||||||
LinearAnimationInstance _instance;
|
LinearAnimationInstance _instance;
|
||||||
final String animationName;
|
final String animationName;
|
||||||
|
bool _stopOnNextApply = false;
|
||||||
|
|
||||||
// Controls the level of mix for the animation, clamped between 0 and 1
|
// Controls the level of mix for the animation, clamped between 0 and 1
|
||||||
double _mix;
|
double _mix;
|
||||||
@ -36,9 +37,27 @@ class SimpleAnimation extends RiveAnimationController<RuntimeArtboard> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void apply(RuntimeArtboard artboard, double elapsedSeconds) {
|
void apply(RuntimeArtboard artboard, double elapsedSeconds) {
|
||||||
_instance.animation.apply(_instance.time, coreContext: artboard, mix: mix);
|
if (_stopOnNextApply) {
|
||||||
if (!_instance.advance(elapsedSeconds)) {
|
|
||||||
isActive = false;
|
isActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We apply before advancing. So we want to stop rendering only once the
|
||||||
|
// last advanced frame has been applied. This means tracking when the last
|
||||||
|
// frame is advanced, ensuring the next apply happens, and then finally
|
||||||
|
// stopping playback. We do this by tracking _stopOnNextApply making sure to
|
||||||
|
// reset it when the controller is re-activated. Fixes #28 and should help
|
||||||
|
// with issues #51 and #56.
|
||||||
|
_instance.animation.apply(_instance.time, coreContext: artboard, mix: mix);
|
||||||
|
if (!_instance.advance(elapsedSeconds)) {
|
||||||
|
_stopOnNextApply = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onActivate() {
|
||||||
|
// We override onActivate to reset stopOnNextApply. This ensures that when
|
||||||
|
// the controller is re-activated after stopping, it doesn't prematurely
|
||||||
|
// stop itself.
|
||||||
|
_stopOnNextApply = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user