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

Side by Side Diff: sky/sdk/lib/animation/animated_value.dart

Issue 1232473003: Delete AnimationValue (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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/BUILD.gn ('k') | sky/sdk/lib/animation/animation_performance.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 'curves.dart';
8 import 'generators.dart';
9
10 typedef void Callback ();
11
12 class AnimatedValue {
13 StreamController<double> _controller = new StreamController<double>.broadcast( sync: true);
14 AnimationGenerator _animation;
15 Completer _completer;
16 double _value;
17
18 AnimatedValue(double initial, { Callback onChange }) {
19 _value = initial;
20 _onChange = onChange;
21 }
22 Callback _onChange;
23
24 // A stream of change in value from |initial|. The stream does not
25 // contain the initial value. Consumers should check the initial value via
26 // the |value| accessor.
27 // TODO(ianh): Rename this to valueStream once we've landed the fn2 fork
28 Stream<double> get onValueChanged => _controller.stream;
29
30 double get value => _value;
31
32 void set value(double value) {
33 stop();
34 _setValue(value);
35 }
36
37 bool get isAnimating => _animation != null;
38
39 void _setValue(double value) {
40 _value = value;
41 _controller.add(_value);
42 if (_onChange != null)
43 _onChange();
44 }
45
46 void _done() {
47 _animation = null;
48 if (_completer == null)
49 return;
50 Completer completer = _completer;
51 _completer = null;
52 completer.complete(_value);
53 }
54
55 void stop() {
56 if (_animation != null) {
57 _animation.cancel(); // will call _done() if it isn't already finished
58 _done();
59 }
60 }
61
62 Future<double> animateTo(double newValue, double duration,
63 { Curve curve: linear, double initialDelay: 0.0 }) {
64 stop();
65
66 _animation = new AnimationGenerator(
67 duration: duration,
68 begin: _value,
69 end: newValue,
70 curve: curve,
71 initialDelay: initialDelay)
72 ..onTick.listen(_setValue, onDone: _done);
73
74 _completer = new Completer();
75 return _completer.future;
76 }
77
78 double get remainingTime {
79 if (_animation == null)
80 return 0.0;
81 return _animation.remainingTime;
82 }
83
84 }
OLDNEW
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/animation/animation_performance.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698