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

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

Issue 1226133004: Switch scroll physics over to using newton (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: analyzer nit 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/generators.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/animation/animated_simulation.dart
diff --git a/sky/sdk/lib/animation/animated_simulation.dart b/sky/sdk/lib/animation/animated_simulation.dart
new file mode 100644
index 0000000000000000000000000000000000000000..38c583542257843c0c654450cd067b56258ed06f
--- /dev/null
+++ b/sky/sdk/lib/animation/animated_simulation.dart
@@ -0,0 +1,60 @@
+// 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 'package:newton/newton.dart';
+
+import 'timeline.dart';
+
+const double _kSecondsPerMillisecond = 1000.0;
+
+class AnimatedSimulation {
+
+ AnimatedSimulation(Function onTick) : _onTick = onTick {
+ _ticker = new Ticker(_tick);
+ }
+
+ final Function _onTick;
+ Ticker _ticker;
+
+ Simulation _simulation;
+ double _startTime;
+
+ double _value = 0.0;
+ double get value => _value;
+
+ Future start(Simulation simulation) {
+ assert(simulation != null);
+ assert(!_ticker.isTicking);
+ _simulation = simulation;
+ _startTime = null;
+ _value = simulation.x(0.0);
+ return _ticker.start();
+ }
+
+ void stop() {
+ _simulation = null;
+ _startTime = null;
+ _value = 0.0;
+ _ticker.stop();
+ }
+
+ bool get isAnimating => _ticker.isTicking;
+
+ void _tick(double timeStamp) {
+ if (_startTime == null)
+ _startTime = timeStamp;
+
+ double timeInSeconds = (timeStamp - _startTime) / _kSecondsPerMillisecond;
+ _value = _simulation.x(timeInSeconds);
+ final bool isLastTick = _simulation.isDone(timeInSeconds);
+
+ _onTick(_value);
+
+ if (isLastTick)
+ stop();
+ }
+
+}
« no previous file with comments | « sky/sdk/example/widgets/card_collection.dart ('k') | sky/sdk/lib/animation/generators.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698