From 67f85e35bad6f1d210d8075db7b01c8bee1648bb Mon Sep 17 00:00:00 2001 From: Hixie Date: Mon, 13 Jul 2015 11:11:19 -0700 Subject: [PATCH] Trivial code style changes in animation code. R=mpcomplete@chromium.org Review URL: https://codereview.chromium.org/1232403004 . --- sdk/lib/animation/animation_performance.dart | 6 ++++- sdk/lib/widgets/animation_builder.dart | 23 +++++++++++--------- sdk/lib/widgets/material.dart | 12 ++++++---- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/sdk/lib/animation/animation_performance.dart b/sdk/lib/animation/animation_performance.dart index 8d8efac0d4e..b857ee957ef 100644 --- a/sdk/lib/animation/animation_performance.dart +++ b/sdk/lib/animation/animation_performance.dart @@ -7,10 +7,11 @@ import 'package:sky/animation/curves.dart'; abstract class AnimatedVariable { void setFraction(double t); + String toString(); } class AnimatedType extends AnimatedVariable { - AnimatedType(this.begin, {this.end, this.curve: linear}) { + AnimatedType(this.begin, { this.end, this.curve: linear }) { value = begin; } @@ -25,6 +26,8 @@ class AnimatedType extends AnimatedVariable { value = begin + (end - begin) * curve.transform(t); } } + + String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)'; } class AnimatedList extends AnimatedVariable { @@ -34,6 +37,7 @@ class AnimatedList extends AnimatedVariable { for (AnimatedVariable variable in variables) variable.setFraction(t); } + String toString() => 'AnimatedList([$variables])'; } // This class manages a "performance" - a collection of values that change diff --git a/sdk/lib/widgets/animation_builder.dart b/sdk/lib/widgets/animation_builder.dart index f91f8f5b2d4..15cff58ad11 100644 --- a/sdk/lib/widgets/animation_builder.dart +++ b/sdk/lib/widgets/animation_builder.dart @@ -15,6 +15,9 @@ import 'package:sky/widgets/basic.dart'; // animated properties. Use syncFields to update the Container's properties, // which will optionally animate them using an AnimationPerformance. class AnimationBuilder { + + AnimationBuilder(); + AnimatedType opacity; AnimatedType position; AnimatedType shadow; @@ -27,10 +30,8 @@ class AnimationBuilder { Map _variableToPerformance = new Map(); - AnimationBuilder(); - AnimationPerformance createPerformance(List variables, - {Duration duration}) { + { Duration duration }) { AnimationPerformance performance = new AnimationPerformance() ..duration = duration ..variable = new AnimatedList(variables); @@ -65,10 +66,12 @@ class AnimationBuilder { return current; } - void updateFields({ AnimatedType shadow, - AnimatedColor backgroundColor, - double borderRadius, - Shape shape }) { + void updateFields({ + AnimatedType shadow, + AnimatedColor backgroundColor, + double borderRadius, + Shape shape + }) { _updateField(this.shadow, shadow); _updateField(this.backgroundColor, backgroundColor); this.borderRadius = borderRadius; @@ -77,7 +80,7 @@ class AnimationBuilder { void _updateField(AnimatedType variable, AnimatedType sourceVariable) { if (variable == null) - return; // TODO(mpcomplete): Should we handle transition from null? + return; // TODO(mpcomplete): Should we handle transition from null? AnimationPerformance performance = _variableToPerformance[variable]; if (performance == null) { @@ -99,8 +102,8 @@ class AnimationBuilder { } class AnimatedColor extends AnimatedType { - AnimatedColor(Color begin, {Color end, Curve curve: linear}) - : super(begin, end: end, curve: curve); + AnimatedColor(Color begin, { Color end, Curve curve: linear }) + : super(begin, end: end, curve: curve); void setFraction(double t) { value = lerpColor(begin, end, t); diff --git a/sdk/lib/widgets/material.dart b/sdk/lib/widgets/material.dart index cc7ebffb9af..107193b4ebe 100644 --- a/sdk/lib/widgets/material.dart +++ b/sdk/lib/widgets/material.dart @@ -39,18 +39,22 @@ class Material extends AnimatedComponent { int level; Color color; - AnimationBuilder _builder; + final AnimationBuilder _builder = new AnimationBuilder(); void initState() { - _builder = new AnimationBuilder() + _builder ..shadow = new AnimatedType(level.toDouble()) ..backgroundColor = _getBackgroundColor(type, color) ..borderRadius = edges[type] ..shape = type == MaterialType.circle ? Shape.circle : Shape.rectangle; watchPerformance(_builder.createPerformance( - [_builder.shadow], duration: _kAnimateShadowDuration)); + [_builder.shadow], + duration: _kAnimateShadowDuration + )); watchPerformance(_builder.createPerformance( - [_builder.backgroundColor], duration: _kAnimateColorDuration)); + [_builder.backgroundColor], + duration: _kAnimateColorDuration + )); super.initState(); }