mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Trivial code style changes in animation code.
R=mpcomplete@chromium.org Review URL: https://codereview.chromium.org/1232403004 .
This commit is contained in:
parent
989aea10fc
commit
67f85e35ba
@ -7,10 +7,11 @@ import 'package:sky/animation/curves.dart';
|
||||
|
||||
abstract class AnimatedVariable {
|
||||
void setFraction(double t);
|
||||
String toString();
|
||||
}
|
||||
|
||||
class AnimatedType<T extends dynamic> 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<T extends dynamic> 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
|
||||
|
||||
@ -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<double> opacity;
|
||||
AnimatedType<Point> position;
|
||||
AnimatedType<double> shadow;
|
||||
@ -27,10 +30,8 @@ class AnimationBuilder {
|
||||
Map<AnimatedVariable, AnimationPerformance> _variableToPerformance =
|
||||
new Map<AnimatedVariable, AnimationPerformance>();
|
||||
|
||||
AnimationBuilder();
|
||||
|
||||
AnimationPerformance createPerformance(List<AnimatedType> 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<double> shadow,
|
||||
AnimatedColor backgroundColor,
|
||||
double borderRadius,
|
||||
Shape shape }) {
|
||||
void updateFields({
|
||||
AnimatedType<double> 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<Color> {
|
||||
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);
|
||||
|
||||
@ -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<double>(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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user