| 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 'timeline.dart'; | 5 import 'timeline.dart'; |
| 6 import 'curves.dart'; | 6 import 'curves.dart'; |
| 7 | 7 |
| 8 // TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't | 8 // TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't |
| 9 // have 2 different ways to animate values. | 9 // have 2 different ways to animate values. |
| 10 abstract class AnimatedVariable { | 10 abstract class AnimatedVariable { |
| 11 void setFraction(double t); | 11 void setFraction(double t); |
| 12 } | 12 } |
| 13 | 13 |
| 14 class AnimatedType<T extends dynamic> extends AnimatedVariable { | 14 class AnimatedType<T extends dynamic> extends AnimatedVariable { |
| 15 T value; | 15 AnimatedType(this.begin, {this.end, this.curve: linear}) { |
| 16 T begin, end; | 16 _value = begin; |
| 17 final Curve curve; | 17 } |
| 18 | 18 |
| 19 AnimatedType(this.begin, {this.end, this.curve: linear}) { | 19 T begin; |
| 20 value = begin; | 20 T end; |
| 21 } | 21 Curve curve; |
| 22 |
| 23 T _value; |
| 24 T get value => _value; |
| 22 | 25 |
| 23 void setFraction(double t) { | 26 void setFraction(double t) { |
| 24 if (end != null) { | 27 if (end != null) { |
| 25 // TODO(mpcomplete): Reverse the timeline and curve. | 28 // TODO(mpcomplete): Reverse the timeline and curve. |
| 26 value = begin + (end - begin) * curve.transform(t); | 29 _value = begin + (end - begin) * curve.transform(t); |
| 27 } | 30 } |
| 28 } | 31 } |
| 29 } | 32 } |
| 30 | 33 |
| 31 // This class manages a "performance" - a collection of values that change | 34 // This class manages a "performance" - a collection of values that change |
| 32 // based on a timeline. For example, a performance may handle an animation | 35 // based on a timeline. For example, a performance may handle an animation |
| 33 // of a menu opening by sliding and fading in (changing Y value and opacity) | 36 // of a menu opening by sliding and fading in (changing Y value and opacity) |
| 34 // over .5 seconds. The performance can move forwards (present) or backwards | 37 // over .5 seconds. The performance can move forwards (present) or backwards |
| 35 // (dismiss). A consumer may also take direct control of the timeline by | 38 // (dismiss). A consumer may also take direct control of the timeline by |
| 36 // manipulating |progress|, or |fling| the timeline causing a physics-based | 39 // manipulating |progress|, or |fling| the timeline causing a physics-based |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 timeline.stop(); | 106 timeline.stop(); |
| 104 if (remainingDistance != 0.0) | 107 if (remainingDistance != 0.0) |
| 105 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); | 108 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); |
| 106 } | 109 } |
| 107 | 110 |
| 108 void _tick(double t) { | 111 void _tick(double t) { |
| 109 variable.setFraction(t); | 112 variable.setFraction(t); |
| 110 _notifyListeners(); | 113 _notifyListeners(); |
| 111 } | 114 } |
| 112 } | 115 } |
| OLD | NEW |