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

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

Issue 1233653003: Add support for "flinging" the animation timeline with a spring force. So far, (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: . 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/lib/animation/animated_simulation.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 11c9822d71b44c716c0a772a448fc92af8f8e4fa..6864861f9f9f96898255f9aca3557baf62fc7352 100644
--- a/sky/sdk/lib/animation/animation_performance.dart
+++ b/sky/sdk/lib/animation/animation_performance.dart
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'package:newton/newton.dart';
import 'package:sky/animation/timeline.dart';
import 'package:sky/animation/curves.dart';
@@ -110,15 +111,11 @@ class AnimationPerformance {
}
// Resume animating in a direction, with the given velocity.
- // TODO(mpcomplete): this should be a force with friction so it slows over
- // time.
+ // TODO(mpcomplete): Allow user to specify the Simulation.
void fling({double velocity: 1.0}) {
- double target = velocity.sign < 0.0 ? 0.0 : 1.0;
- double distance = (target - timeline.value).abs();
- double duration = distance / velocity.abs();
-
- if (distance > 0.0)
- timeline.animateTo(target, duration: duration);
+ Simulation simulation =
+ timeline.defaultSpringSimulation(velocity: velocity);
+ timeline.fling(simulation);
}
final List<Function> _listeners = new List<Function>();
@@ -141,7 +138,7 @@ class AnimationPerformance {
double remainingDistance = (target - timeline.value).abs();
timeline.stop();
if (remainingDistance != 0.0)
- timeline.animateTo(target, duration: remainingDistance * duration.inMilliseconds);
+ timeline.animateTo(target, duration: duration * remainingDistance);
}
void _tick(double t) {
« no previous file with comments | « sky/sdk/lib/animation/animated_simulation.dart ('k') | sky/sdk/lib/animation/timeline.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698