| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:vector_math/vector_math.dart'; | 5 import 'package:vector_math/vector_math.dart'; |
| 6 | 6 |
| 7 import '../animation/animation_performance.dart'; | 7 import '../animation/animation_performance.dart'; |
| 8 import '../animation/curves.dart'; | 8 import '../animation/curves.dart'; |
| 9 import '../base/lerp.dart'; | 9 import '../base/lerp.dart'; |
| 10 import '../painting/box_painter.dart'; | 10 import '../painting/box_painter.dart'; |
| 11 import '../theme/shadows.dart'; | 11 import '../theme/shadows.dart'; |
| 12 import 'basic.dart'; | 12 import 'basic.dart'; |
| 13 | 13 |
| 14 // This class builds a Container object from a collection of optionally- | 14 // This class builds a Container object from a collection of optionally- |
| 15 // animated properties. Use syncFields to update the Container's properties, | 15 // animated properties. Use syncFields to update the Container's properties, |
| 16 // which will optionally animate them using an AnimationPerformance. | 16 // which will optionally animate them using an AnimationPerformance. |
| 17 class AnimatedContainer { | 17 class AnimationBuilder { |
| 18 AnimatedType<double> opacity; | 18 AnimatedType<double> opacity; |
| 19 AnimatedType<Point> position; | 19 AnimatedType<Point> position; |
| 20 AnimatedType<double> shadow; | 20 AnimatedType<double> shadow; |
| 21 AnimatedColor backgroundColor; | 21 AnimatedColor backgroundColor; |
| 22 | 22 |
| 23 // These don't animate, but are used to build the Container anyway. | 23 // These don't animate, but are used to build the AnimationBuilder anyway. |
| 24 double borderRadius; | 24 double borderRadius; |
| 25 Shape shape; | 25 Shape shape; |
| 26 | 26 |
| 27 Map<AnimatedVariable, AnimationPerformance> _variableToPerformance = | 27 Map<AnimatedVariable, AnimationPerformance> _variableToPerformance = |
| 28 new Map<AnimatedVariable, AnimationPerformance>(); | 28 new Map<AnimatedVariable, AnimationPerformance>(); |
| 29 | 29 |
| 30 AnimatedContainer(); | 30 AnimationBuilder(); |
| 31 | 31 |
| 32 AnimationPerformance createPerformance(List<AnimatedType> variables, | 32 AnimationPerformance createPerformance(List<AnimatedType> variables, |
| 33 {Duration duration}) { | 33 {Duration duration}) { |
| 34 AnimationPerformance performance = new AnimationPerformance() | 34 AnimationPerformance performance = new AnimationPerformance() |
| 35 ..duration = duration | 35 ..duration = duration |
| 36 ..variable = new AnimatedList(variables); | 36 ..variable = new AnimatedList(variables); |
| 37 for (AnimatedVariable variable in variables) | 37 for (AnimatedVariable variable in variables) |
| 38 _variableToPerformance[variable] = performance; | 38 _variableToPerformance[variable] = performance; |
| 39 return performance; | 39 return performance; |
| 40 } | 40 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 58 current = new Transform(transform: transform, child: current); | 58 current = new Transform(transform: transform, child: current); |
| 59 } | 59 } |
| 60 | 60 |
| 61 if (opacity != null) { | 61 if (opacity != null) { |
| 62 current = new Opacity(opacity: opacity.value, child: current); | 62 current = new Opacity(opacity: opacity.value, child: current); |
| 63 } | 63 } |
| 64 | 64 |
| 65 return current; | 65 return current; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void syncFields(AnimatedContainer source) { | 68 void updateFields({ AnimatedType<double> shadow, |
| 69 _syncField(position, source.position); | 69 AnimatedColor backgroundColor, |
| 70 _syncField(shadow, source.shadow); | 70 double borderRadius, |
| 71 _syncField(backgroundColor, source.backgroundColor); | 71 Shape shape }) { |
| 72 | 72 _updateField(this.shadow, shadow); |
| 73 borderRadius = source.borderRadius; | 73 _updateField(this.backgroundColor, backgroundColor); |
| 74 shape = source.shape; | 74 this.borderRadius = borderRadius; |
| 75 this.shape = shape; |
| 75 } | 76 } |
| 76 | 77 |
| 77 void _syncField(AnimatedType variable, AnimatedType sourceVariable) { | 78 void _updateField(AnimatedType variable, AnimatedType sourceVariable) { |
| 78 if (variable == null) | 79 if (variable == null) |
| 79 return; // TODO(mpcomplete): Should we handle transition from null? | 80 return; // TODO(mpcomplete): Should we handle transition from null? |
| 80 | 81 |
| 81 AnimationPerformance performance = _variableToPerformance[variable]; | 82 AnimationPerformance performance = _variableToPerformance[variable]; |
| 82 if (performance == null) { | 83 if (performance == null) { |
| 83 // If there's no performance, no need to animate. | 84 // If there's no performance, no need to animate. |
| 84 if (sourceVariable != null) | 85 if (sourceVariable != null) |
| 85 variable.value = sourceVariable.value; | 86 variable.value = sourceVariable.value; |
| 86 return; | 87 return; |
| 87 } | 88 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 112 | 113 |
| 113 int level1 = level.floor(); | 114 int level1 = level.floor(); |
| 114 int level2 = level.ceil(); | 115 int level2 = level.ceil(); |
| 115 double t = level - level1.toDouble(); | 116 double t = level - level1.toDouble(); |
| 116 | 117 |
| 117 List<BoxShadow> shadow = new List<BoxShadow>(); | 118 List<BoxShadow> shadow = new List<BoxShadow>(); |
| 118 for (int i = 0; i < shadows[level1].length; ++i) | 119 for (int i = 0; i < shadows[level1].length; ++i) |
| 119 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t)); | 120 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t)); |
| 120 return shadow; | 121 return shadow; |
| 121 } | 122 } |
| OLD | NEW |