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

Side by Side Diff: sky/sdk/lib/widgets/animated_component.dart

Issue 1233433002: Animate the snack bar in the stocks app. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: renmae 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/example/stocks/lib/stock_home.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'dart:async'; 5 import 'dart:async';
6 6
7 import '../animation/animated_value.dart'; 7 import '../animation/animated_value.dart';
8 import '../animation/animation_performance.dart'; 8 import '../animation/animation_performance.dart';
9 import 'basic.dart'; 9 import 'basic.dart';
10 10
11 class _AnimationEntry { 11 class _AnimationEntry {
12 _AnimationEntry(this.value); 12 _AnimationEntry(this.value);
13 final AnimatedValue value; 13 final AnimatedValue value;
14 StreamSubscription<double> subscription; 14 StreamSubscription<double> subscription;
15 } 15 }
16 16
17 abstract class AnimatedComponent extends StatefulComponent { 17 abstract class AnimatedComponent extends StatefulComponent {
18 18
19 AnimatedComponent({ String key }) : super(key: key); 19 AnimatedComponent({ String key }) : super(key: key);
20 20
21 void syncFields(AnimatedComponent source) { } 21 void syncFields(AnimatedComponent source) { }
22 22
23 final List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>(); 23 final List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>();
24 final List<AnimationPerformance> _watchedPerformances = new List<AnimationPerf ormance>(); 24 final List<AnimationPerformance> _watchedPerformances = new List<AnimationPerf ormance>();
25 25
26 void watch(AnimatedValue value) { 26 void watch(AnimatedValue value) {
27 assert(!mounted);
28 // TODO(ianh): we really should assert that we're not doing this 27 // TODO(ianh): we really should assert that we're not doing this
29 // in the constructor since doing it there is pointless and 28 // in the constructor since doing it there is pointless and
30 // expensive, since we'll be doing it for every copy of the object 29 // expensive, since we'll be doing it for every copy of the object
31 // even though only the first one will use it (since we're 30 // even though only the first one will use it (since we're
32 // stateful, the others will all be discarded early). 31 // stateful, the others will all be discarded early).
32 assert(!mounted);
33 _animatedFields.add(new _AnimationEntry(value)); 33 _animatedFields.add(new _AnimationEntry(value));
34 } 34 }
35 35
36 void watchPerformance(AnimationPerformance performance) { 36 void watchPerformance(AnimationPerformance performance) {
37 assert(!mounted);
38 assert(!_watchedPerformances.contains(performance)); 37 assert(!_watchedPerformances.contains(performance));
39 _watchedPerformances.add(performance); 38 _watchedPerformances.add(performance);
39 if (mounted)
40 performance.addListener(scheduleBuild);
40 } 41 }
41 42
42 void didMount() { 43 void didMount() {
43 for (_AnimationEntry entry in _animatedFields) { 44 for (_AnimationEntry entry in _animatedFields) {
44 entry.subscription = entry.value.onValueChanged.listen((_) { 45 entry.subscription = entry.value.onValueChanged.listen((_) {
45 scheduleBuild(); 46 scheduleBuild();
46 }); 47 });
47 } 48 }
48 49
49 for (AnimationPerformance performance in _watchedPerformances) 50 for (AnimationPerformance performance in _watchedPerformances)
50 performance.addListener(scheduleBuild); 51 performance.addListener(scheduleBuild);
51 52
52 super.didMount(); 53 super.didMount();
53 } 54 }
54 55
55 void didUnmount() { 56 void didUnmount() {
56 for (_AnimationEntry entry in _animatedFields) { 57 for (_AnimationEntry entry in _animatedFields) {
57 assert(entry.subscription != null); 58 assert(entry.subscription != null);
58 entry.subscription.cancel(); 59 entry.subscription.cancel();
59 entry.subscription = null; 60 entry.subscription = null;
60 } 61 }
61 62
62 for (AnimationPerformance performance in _watchedPerformances) 63 for (AnimationPerformance performance in _watchedPerformances)
63 performance.removeListener(scheduleBuild); 64 performance.removeListener(scheduleBuild);
64 65
65 super.didUnmount(); 66 super.didUnmount();
66 } 67 }
67 68
68 } 69 }
OLDNEW
« no previous file with comments | « sky/sdk/example/stocks/lib/stock_home.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698