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

Side by Side Diff: sky/framework/animation/generator.dart

Issue 1005753002: Scrollable should settle back to 0.0 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | sky/framework/components/ink_splash.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'curves.dart'; 5 import 'curves.dart';
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 import 'dart:sky' as sky; 8 import 'dart:sky' as sky;
9 9
10 class FrameGenerator { 10 class FrameGenerator {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 class AnimationGenerator extends FrameGenerator { 54 class AnimationGenerator extends FrameGenerator {
55 Stream<double> get onTick => _stream; 55 Stream<double> get onTick => _stream;
56 final double initialDelay; 56 final double initialDelay;
57 final double duration; 57 final double duration;
58 final double begin; 58 final double begin;
59 final double end; 59 final double end;
60 final Curve curve; 60 final Curve curve;
61 Stream<double> _stream; 61 Stream<double> _stream;
62 bool _done = false; 62 bool _done = false;
63 63
64 AnimationGenerator(this.duration, { 64 AnimationGenerator({
65 this.initialDelay: 0.0, 65 this.initialDelay: 0.0,
66 this.duration,
66 this.begin: 0.0, 67 this.begin: 0.0,
67 this.end: 1.0, 68 this.end: 1.0,
68 this.curve: linear, 69 this.curve: linear,
69 Function onDone 70 Function onDone
70 }):super(onDone: onDone) { 71 }):super(onDone: onDone) {
71 assert(duration > 0); 72 assert(duration != null && duration > 0.0);
72 double startTime = 0.0; 73 double startTime = 0.0;
73 _stream = super.onTick.map((timeStamp) { 74 _stream = super.onTick.map((timeStamp) {
74 if (startTime == 0.0) 75 if (startTime == 0.0)
75 startTime = timeStamp; 76 startTime = timeStamp;
76 77
77 double t = (timeStamp - (startTime + initialDelay)) / duration; 78 double t = (timeStamp - (startTime + initialDelay)) / duration;
78 return math.max(0.0, math.min(t, 1.0)); 79 return math.max(0.0, math.min(t, 1.0));
79 }) 80 })
80 .takeWhile(_checkForCompletion) // 81 .takeWhile(_checkForCompletion) //
81 .where((t) => t >= 0.0) 82 .where((t) => t >= 0.0)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (_animation != null) { 126 if (_animation != null) {
126 _animation.cancel(); 127 _animation.cancel();
127 _animation = null; 128 _animation = null;
128 } 129 }
129 } 130 }
130 131
131 void animateTo(double newValue, double duration, 132 void animateTo(double newValue, double duration,
132 { Curve curve: linear, double initialDelay: 0.0 }) { 133 { Curve curve: linear, double initialDelay: 0.0 }) {
133 stop(); 134 stop();
134 135
135 _animation = new AnimationGenerator(duration, begin: _value, end: newValue, 136 _animation = new AnimationGenerator(
136 curve: curve, initialDelay: initialDelay); 137 duration: duration,
138 begin: _value,
139 end: newValue,
140 curve: curve,
141 initialDelay: initialDelay);
137 142
138 _animation.onTick.listen(_setValue, onDone: () { 143 _animation.onTick.listen(_setValue, onDone: () {
139 _animation = null; 144 _animation = null;
140 }); 145 });
141 } 146 }
142 } 147 }
OLDNEW
« no previous file with comments | « no previous file | sky/framework/components/ink_splash.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698