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

Unified Diff: sky/examples/fn/widgets/animationgenerator.dart

Issue 975153002: fn-drawer sometimes doesn't tick closed (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Use more of the stream machinery Created 5 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/fn/widgets/animationgenerator.dart
diff --git a/sky/examples/fn/widgets/animationgenerator.dart b/sky/examples/fn/widgets/animationgenerator.dart
index a7409345f2ef4067a7c99e7e3b919d92addb7908..5c163b6a7bd41ca63a3a1dce4b42ce8ce12ec1de 100644
--- a/sky/examples/fn/widgets/animationgenerator.dart
+++ b/sky/examples/fn/widgets/animationgenerator.dart
@@ -45,8 +45,6 @@ class FrameGenerator {
}
}
-const double _kFrameTime = 1000 / 60;
-
class AnimationGenerator extends FrameGenerator {
Stream<double> get onTick => _stream;
@@ -55,6 +53,7 @@ class AnimationGenerator extends FrameGenerator {
final double end;
final Curve curve;
Stream<double> _stream;
+ bool _done = false;
AnimationGenerator(this.duration, {
this.begin: 0.0,
@@ -64,24 +63,23 @@ class AnimationGenerator extends FrameGenerator {
}):super(onDone: onDone) {
double startTime = 0.0;
double targetTime = 0.0;
- bool done = false;
_stream = super.onTick.map((timeStamp) {
if (startTime == 0.0) {
startTime = timeStamp;
targetTime = startTime + duration;
}
-
- // Clamp the final frame to target time so we terminate the series with
- // 1.0 exactly.
- if ((timeStamp - targetTime).abs() <= _kFrameTime) {
- return 1.0;
- }
-
- return (timeStamp - startTime) / duration;
+ return math.min((timeStamp - startTime) / duration, 1.0);
})
- .takeWhile((t) => t <= 1.0)
+ .takeWhile(_checkForCompletion)
.map((t) => begin + (end - begin) * curve.transform(t));
}
+
+ bool _checkForCompletion(double t) {
+ if (_done)
+ return false;
+ _done = t >= 1;
+ return true;
+ }
}
double _evaluateCubic(double a, double b, double m) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698