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

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

Issue 1027633003: [Effen] Add AnimatedComponent base class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: moar 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
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 '../fn.dart'; 5 import '../fn.dart';
6 import 'curves.dart'; 6 import 'curves.dart';
7 import 'dart:async'; 7 import 'dart:async';
8 import 'generators.dart'; 8 import 'generators.dart';
9 9
10 class AnimatedValue { 10 class AnimatedValue {
11 StreamController _controller = new StreamController(sync: true); 11 StreamController _controller = new StreamController(sync: true);
12 AnimationGenerator _animation; 12 AnimationGenerator _animation;
13 double _value; 13 double _value;
14 14
15 AnimatedValue(double initial) { 15 AnimatedValue(double initial) {
16 value = initial; 16 _value = initial;
rafaelw 2015/03/20 05:36:00 Note: this prevents the initial value from being b
abarth-chromium 2015/03/20 05:41:49 Maybe add a comment explaining this subtle point?
rafaelw 2015/03/20 05:52:31 Done.
17 } 17 }
18 18
19 Stream<double> get onValueChanged => _controller.stream; 19 Stream<double> get onValueChanged => _controller.stream;
20 20
21 double get value => _value; 21 double get value => _value;
22 22
23 void set value(double value) { 23 void set value(double value) {
24 stop(); 24 stop();
25 _setValue(value); 25 _setValue(value);
26 } 26 }
(...skipping 21 matching lines...) Expand all
48 begin: _value, 48 begin: _value,
49 end: newValue, 49 end: newValue,
50 curve: curve, 50 curve: curve,
51 initialDelay: initialDelay); 51 initialDelay: initialDelay);
52 52
53 _animation.onTick.listen(_setValue, onDone: () { 53 _animation.onTick.listen(_setValue, onDone: () {
54 _animation = null; 54 _animation = null;
55 }); 55 });
56 } 56 }
57 } 57 }
58
59 class AnimatedValueListener {
60 final Component _component;
61 final AnimatedValue _value;
62 StreamSubscription<double> _subscription;
63
64 AnimatedValueListener(this._component, this._value);
65
66 double get value => _value == null ? null : _value.value;
67
68 void ensureListening() {
69 if (_subscription != null || _value == null)
70 return;
71 _subscription = _value.onValueChanged.listen((_) {
72 _component.scheduleBuild();
73 });
74 }
75
76 void stopListening() {
77 if (_subscription == null)
78 return;
79 _subscription.cancel();
80 _subscription = null;
81 }
82 }
OLDNEW
« no previous file with comments | « no previous file | sky/framework/components/animated_component.dart » ('j') | sky/framework/components/animated_component.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698