sample flutter changes for discussion

This commit is contained in:
Maxwell Talbot
2022-05-04 13:51:43 +01:00
parent 6bcdaeac77
commit 735021b7fb
4 changed files with 43 additions and 2 deletions

View File

@ -29,4 +29,12 @@ class NestedSimpleAnimation extends NestedSimpleAnimationBase {
}
super.advance(elapsedSeconds, mountedArtboard);
}
void goTo(double time, MountedArtboard mountedArtboard) {
if (isPlaying) {
linearAnimationInstance?.goto(time);
linearAnimationInstance?.apply(mountedArtboard, mix);
linearAnimationInstance?.needsApply = false;
}
}
}

View File

@ -153,21 +153,30 @@ class Artboard extends ArtboardBase with ShapePaintContainer {
}
final Set<NestedArtboard> _activeNestedArtboards = {};
Set<NestedArtboard> get activeNestedArtboards => _activeNestedArtboards;
/// Update any dirty components in this artboard.
bool advance(double elapsedSeconds, {bool nested = false}) {
bool didUpdate = false;
bool handleNestedArtboards = true;
for (final controller in _animationControllers) {
if (controller.suppressesNestedArtboards) {
handleNestedArtboards = false;
}
if (controller.isActive) {
controller.apply(context, elapsedSeconds);
didUpdate = true;
}
}
// NOTE: i think this works out if the nested artboard should still be
// animating...
if (updateComponents() || didUpdate) {
didUpdate = true;
}
if (nested) {
// TODO: talk about this.
if (nested && handleNestedArtboards) {
var active = _activeNestedArtboards.toList(growable: false);
for (final activeNestedArtboard in active) {
activeNestedArtboard.advance(elapsedSeconds);

View File

@ -1,5 +1,6 @@
import 'dart:ui';
import 'package:rive/rive.dart';
import 'package:rive/src/core/core.dart';
import 'package:rive/src/generated/nested_artboard_base.dart';
import 'package:rive/src/rive_core/animation/nested_remap_animation.dart';
@ -46,7 +47,6 @@ class NestedArtboard extends NestedArtboardBase {
@override
void artboardIdChanged(int from, int to) {}
@override
void childAdded(Component child) {
super.childAdded(child);
@ -88,6 +88,22 @@ class NestedArtboard extends NestedArtboardBase {
mountedArtboard!.advance(elapsedSeconds);
}
void goTo(double seconds) {
if (mountedArtboard == null) {
return;
}
for (final animation in _animations) {
if (animation.isEnabled) {
if (animation is NestedSimpleAnimation) {
animation.goTo(seconds, mountedArtboard!);
}
}
}
// Gotta advance the artboard to make it dirty?
// (if we skip this no redraw)
mountedArtboard!.advance(0.0);
}
@override
void update(int dirt) {
super.update(dirt);

View File

@ -6,6 +6,14 @@ abstract class RiveAnimationController<T> {
final _isActive = ValueNotifier<bool>(false);
ValueListenable<bool> get isActiveChanged => _isActive;
// TODO: this is a hack.
// Ideally nestedArtboards are not run in the Artboard.advance, but instead
// always controlled by AnimationControllers.
// SimpleAnimationControllers kinda throw a spanner in the works here.
// unless we do some magic that means multiple simple animation controllers
// won't all compete for advancing the nested artboard....
final suppressesNestedArtboards = false;
bool get isActive => _isActive.value;
set isActive(bool value) {
if (_isActive.value != value) {