| 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:sky/animation/timeline.dart'; | 5 import 'package:sky/animation/timeline.dart'; |
| 6 import 'package:sky/animation/curves.dart'; | 6 import 'package:sky/animation/curves.dart'; |
| 7 | 7 |
| 8 abstract class AnimatedVariable { | 8 abstract class AnimatedVariable { |
| 9 void setFraction(double t); | 9 void setFraction(double t); |
| 10 String toString(); | 10 String toString(); |
| 11 } | 11 } |
| 12 | 12 |
| 13 class AnimatedType<T extends dynamic> extends AnimatedVariable { | 13 class AnimatedType<T extends dynamic> extends AnimatedVariable { |
| 14 AnimatedType(this.begin, { this.end, this.curve: linear }) { | 14 AnimatedType(this.begin, { this.end, this.curve: linear }) { |
| 15 value = begin; | 15 value = begin; |
| 16 } | 16 } |
| 17 | 17 |
| 18 T value; | 18 T value; |
| 19 T begin; | 19 T begin; |
| 20 T end; | 20 T end; |
| 21 Curve curve; | 21 Curve curve; |
| 22 | 22 |
| 23 void setFraction(double t) { | 23 void setFraction(double t) { |
| 24 if (end != null) { | 24 if (end != null) { |
| 25 // TODO(mpcomplete): Reverse the timeline and curve. | 25 if (t == 1.0) { |
| 26 value = begin + (end - begin) * curve.transform(t); | 26 value = end; |
| 27 } else { |
| 28 // TODO(mpcomplete): Reverse the timeline and curve. |
| 29 value = begin + (end - begin) * curve.transform(t); |
| 30 } |
| 27 } | 31 } |
| 28 } | 32 } |
| 29 | 33 |
| 30 String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)'; | 34 String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)'; |
| 31 } | 35 } |
| 32 | 36 |
| 33 class AnimatedList extends AnimatedVariable { | 37 class AnimatedList extends AnimatedVariable { |
| 34 List<AnimatedVariable> variables; | 38 List<AnimatedVariable> variables; |
| 35 AnimatedList(this.variables); | 39 AnimatedList(this.variables); |
| 36 void setFraction(double t) { | 40 void setFraction(double t) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 timeline.stop(); | 119 timeline.stop(); |
| 116 if (remainingDistance != 0.0) | 120 if (remainingDistance != 0.0) |
| 117 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); | 121 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); |
| 118 } | 122 } |
| 119 | 123 |
| 120 void _tick(double t) { | 124 void _tick(double t) { |
| 121 variable.setFraction(t); | 125 variable.setFraction(t); |
| 122 _notifyListeners(); | 126 _notifyListeners(); |
| 123 } | 127 } |
| 124 } | 128 } |
| OLD | NEW |