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

Unified Diff: sky/framework/animation/simulation.dart

Issue 999423004: Drive overscroll animations with a physics simulation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: More comments Created 5 years, 9 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/framework/animation/scroll_curve.dart ('k') | sky/framework/components/scrollable.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/animation/simulation.dart
diff --git a/sky/framework/animation/simulation.dart b/sky/framework/animation/simulation.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e7904a389267f630da837e82bb4a56715f9b68df
--- /dev/null
+++ b/sky/framework/animation/simulation.dart
@@ -0,0 +1,45 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:async';
+import 'generator.dart';
+import 'kinematics.dart';
+
+class Simulation {
+ Stream<double> get onTick => _stream;
+ final System system;
+
+ FrameGenerator _generator;
+ Stream<double> _stream;
+ double _previousTime = 0.0;
+
+ Simulation(this.system, {Function terminationCondition, Function onDone}) {
+ _generator = new FrameGenerator(onDone: onDone);
+ _stream = _generator.onTick.map(_update);
+
+ if (terminationCondition != null) {
+ bool done = false;
+ _stream = _stream.takeWhile((_) {
+ if (done)
+ return false;
+ done = terminationCondition();
+ return true;
+ });
+ }
+ }
+
+ void cancel() {
+ _generator.cancel();
+ }
+
+ double _update(double timeStamp) {
+ double previousTime = _previousTime;
+ _previousTime = timeStamp;
+ if (previousTime == 0.0)
+ return timeStamp;
+ double deltaT = timeStamp - previousTime;
+ system.update(deltaT);
+ return timeStamp;
+ }
+}
« no previous file with comments | « sky/framework/animation/scroll_curve.dart ('k') | sky/framework/components/scrollable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698