Apply NestedInput initial values

This update applies the initial values for nested inputs (as set in the Inputs panel of the Editor), so that NestedInputs behave in the same way as regular StateMachineInputs. There are a couple of reasons to do this:

1. Currently if you have a nested artboard and set the initial nested input value, it will only apply in the editor when viewing that artboard. If you nest that artboard in another artboard, the initial values do not apply. Similarly, initial nested values do not apply in the runtimes. Currently StateMachineInputs do apply initial values, so this brings NestedInputs in line with that.

2. There was a bug Hernan noticed where there in certain cases, NestedInput values that were keyed on a timeline did not apply properly in cases where the keyed value was the same as the default value. In these cases, the keyed value is ignored because it and the default values were the same. In addition, since the initial value wasn't being applied, the state wasn't being update properly based on the nested input's value.

Diffs=
6d9aa0179 Apply NestedInput initial values (#6140)
92c8f1164 Elastic easing (#6143)

Co-authored-by: Philip Chung <philterdesign@gmail.com>
This commit is contained in:
philter
2023-10-25 05:37:20 +00:00
parent 312a8b0577
commit fa80780c28
3 changed files with 24 additions and 2 deletions

View File

@ -1 +1 @@
c0411df0a74b2aafa18526375cda19f6779a2354
6d9aa017961638f7576a2ea52a8928c813e28dbb

View File

@ -1,6 +1,6 @@
import 'package:rive/src/core/core.dart';
import 'package:rive/src/generated/animation/nested_input_base.dart';
import 'package:rive/src/rive_core/animation/nested_state_machine.dart';
import 'package:rive/src/rive_core/container_component.dart';
import 'package:rive/src/rive_core/nested_artboard.dart';
export 'package:rive/src/generated/animation/nested_input_base.dart';
@ -20,6 +20,16 @@ abstract class NestedInput extends NestedInputBase {
@override
bool validate() => super.validate() && nestedStateMachine != null;
@override
void parentChanged(ContainerComponent? from, ContainerComponent? to) {
super.parentChanged(from, to);
if (nestedStateMachine != null) {
if (!nestedStateMachine!.nestedInputs.contains(this)) {
nestedStateMachine!.nestedInputs.add(this);
}
}
}
void updateValue();
@override

View File

@ -2,6 +2,9 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:rive/src/core/core.dart';
import 'package:rive/src/generated/animation/nested_state_machine_base.dart';
import 'package:rive/src/rive_core/animation/nested_bool.dart';
import 'package:rive/src/rive_core/animation/nested_input.dart';
import 'package:rive/src/rive_core/animation/nested_number.dart';
import 'package:rive/src/rive_core/nested_artboard.dart';
import 'package:rive_common/math.dart';
@ -33,6 +36,9 @@ class NestedStateMachine extends NestedStateMachineBase {
@override
bool get isEnabled => _stateMachineInstance?.isActive ?? false;
final Set<NestedInput> _nestedInputs = {};
Set<NestedInput> get nestedInputs => _nestedInputs;
NestedStateMachineInstance? _stateMachineInstance;
NestedStateMachineInstance? get stateMachineInstance => _stateMachineInstance;
set stateMachineInstance(NestedStateMachineInstance? value) {
@ -42,6 +48,12 @@ class NestedStateMachine extends NestedStateMachineBase {
var from = _stateMachineInstance;
_stateMachineInstance = value;
stateMachineInstanceChanged(from, value);
for (final input in nestedInputs) {
if (input is NestedBool || input is NestedNumber) {
input.updateValue();
}
}
}
void stateMachineInstanceChanged(