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

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

Issue 1092423003: [Effen] Reduce splashes when scrolling. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix comments from eseidel Created 5 years, 8 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/framework/animation/animated_value.dart ('k') | 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 import 'mechanics.dart'; 9 import 'mechanics.dart';
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Stream<double> get onTick => _stream; 61 Stream<double> get onTick => _stream;
62 final double initialDelay; 62 final double initialDelay;
63 final double duration; 63 final double duration;
64 final double begin; 64 final double begin;
65 final double end; 65 final double end;
66 final Curve curve; 66 final Curve curve;
67 67
68 FrameGenerator _generator; 68 FrameGenerator _generator;
69 Stream<double> _stream; 69 Stream<double> _stream;
70 bool _done = false; 70 bool _done = false;
71 double _lastTime;
71 72
72 AnimationGenerator({ 73 AnimationGenerator({
73 this.initialDelay: 0.0, 74 this.initialDelay: 0.0,
74 this.duration, 75 this.duration,
75 this.begin: 0.0, 76 this.begin: 0.0,
76 this.end: 1.0, 77 this.end: 1.0,
77 this.curve: linear, 78 this.curve: linear,
78 Function onDone 79 Function onDone
79 }) { 80 }) {
80 assert(curve != null); 81 assert(curve != null);
81 assert(duration != null && duration > 0.0); 82 assert(duration != null && duration > 0.0);
82 _generator = new FrameGenerator(onDone: onDone); 83 _generator = new FrameGenerator(onDone: onDone);
83 84
84 double startTime = 0.0; 85 double startTime = 0.0;
85 _stream = _generator.onTick.map((timeStamp) { 86 _stream = _generator.onTick.map((timeStamp) {
86 if (startTime == 0.0) 87 if (startTime == 0.0)
87 startTime = timeStamp; 88 startTime = timeStamp;
88 89
89 double t = (timeStamp - (startTime + initialDelay)) / duration; 90 double t = (timeStamp - (startTime + initialDelay)) / duration;
90 return math.max(0.0, math.min(t, 1.0)); 91 _lastTime = math.max(0.0, math.min(t, 1.0));
92 return _lastTime;
91 }) 93 })
92 .takeWhile(_checkForCompletion) 94 .takeWhile(_checkForCompletion)
93 .where((t) => t >= 0.0) 95 .where((t) => t >= 0.0)
94 .map(_transform); 96 .map(_transform);
95 } 97 }
96 98
99 double get remainingTime {
100 if (_lastTime == null)
101 return duration;
102 return duration - _lastTime;
103 }
104
97 void cancel() { 105 void cancel() {
98 _generator.cancel(); 106 _generator.cancel();
99 } 107 }
100 108
101 double _transform(double t) { 109 double _transform(double t) {
102 if (_done) 110 if (_done)
103 return end; 111 return end;
104 return begin + (end - begin) * curve.transform(t); 112 return begin + (end - begin) * curve.transform(t);
105 } 113 }
106 114
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 double _update(double timeStamp) { 152 double _update(double timeStamp) {
145 double previousTime = _previousTime; 153 double previousTime = _previousTime;
146 _previousTime = timeStamp; 154 _previousTime = timeStamp;
147 if (previousTime == 0.0) 155 if (previousTime == 0.0)
148 return timeStamp; 156 return timeStamp;
149 double deltaT = timeStamp - previousTime; 157 double deltaT = timeStamp - previousTime;
150 system.update(deltaT); 158 system.update(deltaT);
151 return timeStamp; 159 return timeStamp;
152 } 160 }
153 } 161 }
OLDNEW
« no previous file with comments | « sky/framework/animation/animated_value.dart ('k') | sky/framework/components/ink_splash.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698