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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:newton/newton.dart';
8
9 import 'timeline.dart';
10
11 const double _kSecondsPerMillisecond = 1000.0;
12
13 class AnimatedSimulation {
14
15 AnimatedSimulation(Function onTick) : _onTick = onTick {
16 _ticker = new Ticker(_tick);
17 }
18
19 final Function _onTick;
20 Ticker _ticker;
21
22 Simulation _simulation;
23 double _startTime;
24
25 double _value = 0.0;
26 double get value => _value;
27
28 Future start(Simulation simulation) {
29 assert(simulation != null);
30 assert(!_ticker.isTicking);
31 _simulation = simulation;
32 _startTime = null;
33 _value = simulation.x(0.0);
34 return _ticker.start();
35 }
36
37 void stop() {
38 _simulation = null;
39 _startTime = null;
40 _value = 0.0;
41 _ticker.stop();
42 }
43
44 bool get isAnimating => _ticker.isTicking;
45
46 void _tick(double timeStamp) {
47 if (_startTime == null)
48 _startTime = timeStamp;
49
50 double timeInSeconds = (timeStamp - _startTime) / _kSecondsPerMillisecond;
51 _value = _simulation.x(timeInSeconds);
52 final bool isLastTick = _simulation.isDone(timeInSeconds);
53
54 _onTick(_value);
55
56 if (isLastTick)
57 stop();
58 }
59
60 }
OLDNEW
« 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