Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Unified Diff: sky/sdk/lib/animation/animation_performance.dart

Issue 1226263003: Break dependency of AnimationPerformance on AnimatedValue (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: remove unused import Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/example/widgets/card_collection.dart ('k') | sky/sdk/lib/animation/timeline.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/animation/animation_performance.dart
diff --git a/sky/sdk/lib/animation/animation_performance.dart b/sky/sdk/lib/animation/animation_performance.dart
index f4179e95ac770b515ba3487261be9e1cefff3b19..6dd5b53c2e5bf3e2c83416287c46ac1103e48c2f 100644
--- a/sky/sdk/lib/animation/animation_performance.dart
+++ b/sky/sdk/lib/animation/animation_performance.dart
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'animated_value.dart';
+import 'timeline.dart';
import 'curves.dart';
// TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't
@@ -34,18 +34,18 @@ class AnimatedType<T extends dynamic> extends AnimatedVariable {
// manipulating |progress|, or |fling| the timeline causing a physics-based
// simulation to take over the progression.
class AnimationPerformance {
+ AnimationPerformance() {
+ _timeline = new Timeline(_tick);
+ }
+
// TODO(mpcomplete): make this a list, or composable somehow.
AnimatedVariable variable;
- // Advances from 0 to 1. On each tick, we'll update our variable's values.
- AnimatedValue timeline = new AnimatedValue(0.0);
// TODO(mpcomplete): duration should be on a director.
Duration duration;
- AnimationPerformance() {
- timeline.onValueChanged.listen((double t) {
- variable.setFraction(t);
- });
- }
+ // Advances from 0 to 1. On each tick, we'll update our variable's values.
+ Timeline _timeline;
+ Timeline get timeline => _timeline;
double get progress => timeline.value;
void set progress(double t) {
@@ -64,13 +64,6 @@ class AnimationPerformance {
_animateTo(0.0);
}
- void _animateTo(double target) {
- double remainingDistance = (target - timeline.value).abs();
- timeline.stop();
- if (remainingDistance != 0.0)
- timeline.animateTo(target, remainingDistance * duration.inMilliseconds);
- }
-
void stop() {
timeline.stop();
}
@@ -84,6 +77,34 @@ class AnimationPerformance {
double duration = distance / velocity.abs();
if (distance > 0.0)
- timeline.animateTo(target, duration, curve: linear);
+ timeline.animateTo(target, duration: duration);
+ }
+
+ final List<Function> _listeners = new List<Function>();
+
+ void addListener(Function listener) {
+ _listeners.add(listener);
+ }
+
+ void removeListener(Function listener) {
+ _listeners.remove(listener);
+ }
+
+ void _notifyListeners() {
+ List<Function> localListeners = new List<Function>.from(_listeners);
+ for (Function listener in localListeners)
+ listener();
+ }
+
+ void _animateTo(double target) {
+ double remainingDistance = (target - timeline.value).abs();
+ timeline.stop();
+ if (remainingDistance != 0.0)
+ timeline.animateTo(target, duration: remainingDistance * duration.inMilliseconds);
+ }
+
+ void _tick(double t) {
+ variable.setFraction(t);
+ _notifyListeners();
}
}
« no previous file with comments | « sky/sdk/example/widgets/card_collection.dart ('k') | sky/sdk/lib/animation/timeline.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698