| Index: sky/framework/animation/animated_value.dart
|
| diff --git a/sky/framework/animation/animation.dart b/sky/framework/animation/animated_value.dart
|
| similarity index 62%
|
| rename from sky/framework/animation/animation.dart
|
| rename to sky/framework/animation/animated_value.dart
|
| index 62b93f676388819dabbb3c8079d9851942e010ff..faf17b6a82b901a7bc9e3d45253a3cfa0cf36cf6 100644
|
| --- a/sky/framework/animation/animation.dart
|
| +++ b/sky/framework/animation/animated_value.dart
|
| @@ -2,11 +2,20 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +import '../fn.dart';
|
| import 'curves.dart';
|
| import 'dart:async';
|
| import 'generators.dart';
|
|
|
| -class Animation {
|
| +class AnimatedValue {
|
| + StreamController _controller = new StreamController(sync: true);
|
| + AnimationGenerator _animation;
|
| + double _value;
|
| +
|
| + AnimatedValue(double initial) {
|
| + value = initial;
|
| + }
|
| +
|
| Stream<double> get onValueChanged => _controller.stream;
|
|
|
| double get value => _value;
|
| @@ -18,12 +27,6 @@ class Animation {
|
|
|
| bool get isAnimating => _animation != null;
|
|
|
| - StreamController _controller = new StreamController(sync: true);
|
| -
|
| - AnimationGenerator _animation;
|
| -
|
| - double _value;
|
| -
|
| void _setValue(double value) {
|
| _value = value;
|
| _controller.add(_value);
|
| @@ -52,3 +55,28 @@ class Animation {
|
| });
|
| }
|
| }
|
| +
|
| +class AnimatedValueListener {
|
| + final Component _component;
|
| + final AnimatedValue _value;
|
| + StreamSubscription<double> _subscription;
|
| +
|
| + AnimatedValueListener(this._component, this._value);
|
| +
|
| + double get value => _value == null ? null : _value.value;
|
| +
|
| + void ensureListening() {
|
| + if (_subscription != null || _value == null)
|
| + return;
|
| + _subscription = _value.onValueChanged.listen((_) {
|
| + _component.scheduleBuild();
|
| + });
|
| + }
|
| +
|
| + void stopListening() {
|
| + if (_subscription == null)
|
| + return;
|
| + _subscription.cancel();
|
| + _subscription = null;
|
| + }
|
| +}
|
|
|