OLD | NEW |
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 '../animation/animated_value.dart'; | 5 import '../animation/animated_value.dart'; |
6 import '../fn2.dart'; | 6 import '../fn2.dart'; |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 typedef void SetterFunction(double value); | 9 typedef void SetterFunction(double value); |
10 | 10 |
11 abstract class AnimatedComponent extends Component { | 11 abstract class AnimatedComponent extends Component { |
12 | 12 |
13 AnimatedComponent({ Object key }) : super(key: key, stateful: true); | 13 AnimatedComponent({ Object key }) : super(key: key, stateful: true); |
14 | 14 |
| 15 void syncFields(AnimatedComponent source) { } |
| 16 |
15 animate(AnimatedValue value, SetterFunction setter) { | 17 animate(AnimatedValue value, SetterFunction setter) { |
16 setter(value.value); | 18 setter(value.value); |
17 StreamSubscription<double> subscription; | 19 StreamSubscription<double> subscription; |
18 onDidMount(() { | 20 onDidMount(() { |
19 subscription = value.onValueChanged.listen((_) { | 21 subscription = value.onValueChanged.listen((_) { |
20 setter(value.value); | 22 setter(value.value); |
21 scheduleBuild(); | 23 scheduleBuild(); |
22 }); | 24 }); |
23 }); | 25 }); |
24 onDidUnmount(() { | 26 onDidUnmount(() { |
25 if (subscription != null) { | 27 if (subscription != null) { |
26 subscription.cancel(); | 28 subscription.cancel(); |
27 subscription = null; | 29 subscription = null; |
28 } | 30 } |
29 }); | 31 }); |
30 } | 32 } |
31 | 33 |
32 } | 34 } |
OLD | NEW |