Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/mix/lib/src/animation/style_animation_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ class _StyleAnimationBuilderState<S extends Spec<S>>
extends State<StyleAnimationBuilder<S>>
with TickerProviderStateMixin {
late StyleAnimationDriver<S> animationDriver;

@override
void initState() {
super.initState();
final spec = widget.spec;
final config = spec.animation;
animationDriver = _createAnimationDriver(config: config, initialSpec: spec);
}
bool _hasInitializedAnimationDriver = false;

StyleAnimationDriver<S> _createAnimationDriver({
required AnimationConfig? config,
Expand Down Expand Up @@ -78,6 +71,24 @@ class _StyleAnimationBuilderState<S extends Spec<S>>
};
}

@override
void didChangeDependencies() {
super.didChangeDependencies();

if (!_hasInitializedAnimationDriver) {
final spec = widget.spec;
animationDriver = _createAnimationDriver(
config: spec.animation,
initialSpec: spec,
);
_hasInitializedAnimationDriver = true;

return;
}

animationDriver.didChangeDependencies();
}

@override
void dispose() {
animationDriver.dispose();
Expand Down
27 changes: 19 additions & 8 deletions packages/mix/lib/src/animation/style_animation_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ abstract class StyleAnimationDriver<S extends Spec<S>> {

// ignore: no-empty-block
void didUpdateSpec(StyleSpec<S> oldSpec, StyleSpec<S> newSpec) {}
// ignore: no-empty-block
void didChangeDependencies() {}
void updateDriver(AnimationConfig config);

/// Execute the animation (curve vs spring).
Expand Down Expand Up @@ -245,14 +247,7 @@ class PhaseAnimationDriver<S extends Spec<S>> extends StyleAnimationDriver<S> {
}

void _setUpAnimation() {
final specs = config.styles
.map((e) => e.resolve(context) as StyleSpec<S>)
.toList();

_tweenSequence = _createTweenSequence(specs, config.curveConfigs);

// Override the animation to use TweenSequence wrapped in a tween
_animation = controller.drive(_PhasedSpecTween(_tweenSequence));
_resolveStyles();

config.trigger?.addListener(_onTriggerChanged);

Expand All @@ -266,6 +261,17 @@ class PhaseAnimationDriver<S extends Spec<S>> extends StyleAnimationDriver<S> {
}
}

void _resolveStyles() {
final specs = config.styles
.map((e) => e.resolve(context) as StyleSpec<S>)
.toList();

_tweenSequence = _createTweenSequence(specs, config.curveConfigs);

// Override the animation to use TweenSequence wrapped in a tween
_animation = controller.drive(_PhasedSpecTween(_tweenSequence));
}

void _onTriggerChanged() {
executeAnimation();
}
Expand Down Expand Up @@ -331,6 +337,11 @@ class PhaseAnimationDriver<S extends Spec<S>> extends StyleAnimationDriver<S> {
await controller.forward(from: 0.0);
}

@override
void didChangeDependencies() {
_resolveStyles();
}

@override
void updateDriver(covariant PhaseAnimationConfig config) {
this.config.trigger?.removeListener(_onTriggerChanged);
Expand Down
Loading
Loading