OLD | NEW |
| (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 '../animation/animated_value.dart'; | |
6 import '../fn2.dart'; | |
7 import 'dart:async'; | |
8 | |
9 typedef void SetterFunction(double value); | |
10 | |
11 class _AnimationEntry { | |
12 _AnimationEntry(this.value, this.setter); | |
13 final AnimatedValue value; | |
14 final SetterFunction setter; | |
15 StreamSubscription<double> subscription; | |
16 } | |
17 | |
18 abstract class AnimatedComponent extends Component { | |
19 | |
20 AnimatedComponent({ Object key }) : super(key: key, stateful: true); | |
21 | |
22 void syncFields(AnimatedComponent source) { } | |
23 | |
24 List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>(); | |
25 | |
26 animate(AnimatedValue value, SetterFunction setter) { | |
27 assert(!mounted); | |
28 setter(value.value); | |
29 _animatedFields.add(new _AnimationEntry(value, setter)); | |
30 } | |
31 | |
32 void didMount() { | |
33 for (_AnimationEntry entry in _animatedFields) { | |
34 entry.subscription = entry.value.onValueChanged.listen((_) { | |
35 entry.setter(entry.value.value); | |
36 scheduleBuild(); | |
37 }); | |
38 } | |
39 super.didMount(); | |
40 } | |
41 | |
42 void didUnmount() { | |
43 for (_AnimationEntry entry in _animatedFields) { | |
44 assert(entry.subscription != null); | |
45 entry.subscription.cancel(); | |
46 entry.subscription = null; | |
47 } | |
48 super.didUnmount(); | |
49 } | |
50 | |
51 } | |
OLD | NEW |