| 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 'animated_value.dart'; | 5 import 'animated_value.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 AnimatedVariable { | 14 class AnimatedType<T extends dynamic> extends AnimatedVariable { |
| 15 T value; | 15 T value; |
| 16 final T begin, end; | 16 final T begin, end; |
| 17 final Curve curve; | 17 final Curve curve; |
| 18 | 18 |
| 19 AnimatedType(this.begin, this.end, {this.curve: linear}) { | 19 AnimatedType(this.begin, this.end, {this.curve: linear}) { |
| 20 value = begin; | 20 value = begin; |
| 21 } | 21 } |
| 22 | 22 |
| 23 void setFraction(double t) { | 23 void setFraction(double t) { |
| 24 // TODO(mpcomplete): Reverse the timeline and curve. | 24 // TODO(mpcomplete): Reverse the timeline and curve. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // time. | 80 // time. |
| 81 void fling({double velocity: 1.0}) { | 81 void fling({double velocity: 1.0}) { |
| 82 double target = velocity.sign < 0.0 ? 0.0 : 1.0; | 82 double target = velocity.sign < 0.0 ? 0.0 : 1.0; |
| 83 double distance = (target - timeline.value).abs(); | 83 double distance = (target - timeline.value).abs(); |
| 84 double duration = distance / velocity.abs(); | 84 double duration = distance / velocity.abs(); |
| 85 | 85 |
| 86 if (distance > 0.0) | 86 if (distance > 0.0) |
| 87 timeline.animateTo(target, duration, curve: linear); | 87 timeline.animateTo(target, duration, curve: linear); |
| 88 } | 88 } |
| 89 } | 89 } |
| OLD | NEW |