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

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

Issue 979283002: Move animationgenerator.dart to sky/framework/animation/generator.dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 | sky/examples/fn/widgets/widgets.dart » ('j') | 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
deleted file mode 100644
index ef916548946b2892db204aaee920b0ae8470ff76..0000000000000000000000000000000000000000
--- a/sky/examples/fn/widgets/animationgenerator.dart
+++ /dev/null
@@ -1,83 +0,0 @@
-part of widgets;
-
-class FrameGenerator {
-
- Function onDone;
- StreamController _controller;
-
- Stream<double> get onTick => _controller.stream;
-
- int _animationId = 0;
- bool _cancelled = false;
-
- FrameGenerator({this.onDone}) {
- _controller = new StreamController(
- sync: true,
- onListen: _scheduleTick,
- onCancel: cancel);
- }
-
- void cancel() {
- if (_cancelled) {
- return;
- }
- if (_animationId != 0) {
- sky.window.cancelAnimationFrame(_animationId);
- }
- _animationId = 0;
- _cancelled = true;
- if (onDone != null) {
- onDone();
- }
- }
-
- void _scheduleTick() {
- assert(_animationId == 0);
- _animationId = sky.window.requestAnimationFrame(_tick);
- }
-
- void _tick(double timeStamp) {
- _animationId = 0;
- _controller.add(timeStamp);
- if (!_cancelled) {
- _scheduleTick();
- }
- }
-}
-
-class AnimationGenerator extends FrameGenerator {
-
- Stream<double> get onTick => _stream;
- final double duration;
- final double begin;
- final double end;
- final Curve curve;
- Stream<double> _stream;
- bool _done = false;
-
- AnimationGenerator(this.duration, {
- this.begin: 0.0,
- this.end: 1.0,
- this.curve: linear,
- Function onDone
- }):super(onDone: onDone) {
- double startTime = 0.0;
- double targetTime = 0.0;
- _stream = super.onTick.map((timeStamp) {
- if (startTime == 0.0) {
- startTime = timeStamp;
- targetTime = startTime + duration;
- }
- return math.min((timeStamp - startTime) / duration, 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;
- }
-}
« no previous file with comments | « no previous file | sky/examples/fn/widgets/widgets.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698