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

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

Issue 1231933006: Use AnimatedContainer for card_collection.dart. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: 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
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 'package:vector_math/vector_math.dart'; 5 import 'package:vector_math/vector_math.dart';
6 6
7 import '../animation/animation_performance.dart'; 7 import '../animation/animation_performance.dart';
8 import '../animation/curves.dart'; 8 import '../animation/curves.dart';
9 import '../base/lerp.dart'; 9 import '../base/lerp.dart';
10 import '../painting/box_painter.dart'; 10 import '../painting/box_painter.dart';
11 import '../theme/shadows.dart'; 11 import '../theme/shadows.dart';
12 import 'basic.dart'; 12 import 'basic.dart';
13 13
14 // This class builds a Container object from a collection of optionally- 14 // This class builds a Container object from a collection of optionally-
15 // animated properties. Use syncFields to update the Container's properties, 15 // animated properties. Use syncFields to update the Container's properties,
16 // which will optionally animate them using an AnimationPerformance. 16 // which will optionally animate them using an AnimationPerformance.
17 class AnimatedContainer { 17 class AnimatedContainer {
18 AnimatedType<double> opacity;
18 AnimatedType<Point> position; 19 AnimatedType<Point> position;
19 AnimatedType<double> shadow; 20 AnimatedType<double> shadow;
20 AnimatedColor backgroundColor; 21 AnimatedColor backgroundColor;
21 22
22 // These don't animate, but are used to build the Container anyway. 23 // These don't animate, but are used to build the Container anyway.
23 double borderRadius; 24 double borderRadius;
24 Shape shape; 25 Shape shape;
25 26
26 Map<AnimatedVariable, AnimationPerformance> _variableToPerformance = 27 Map<AnimatedVariable, AnimationPerformance> _variableToPerformance =
27 new Map<AnimatedVariable, AnimationPerformance>(); 28 new Map<AnimatedVariable, AnimationPerformance>();
28 29
29 AnimatedContainer(); 30 AnimatedContainer();
30 31
31 AnimationPerformance createPerformance(AnimatedType variable, 32 AnimationPerformance createPerformance(List<AnimatedType> variables,
32 {Duration duration}) { 33 {Duration duration}) {
33 AnimationPerformance performance = new AnimationPerformance() 34 AnimationPerformance performance = new AnimationPerformance()
34 ..duration = duration 35 ..duration = duration
35 ..variable = variable; 36 ..variable = new AnimatedList(variables);
36 _variableToPerformance[variable] = performance; 37 for (AnimatedVariable variable in variables)
38 _variableToPerformance[variable] = performance;
37 return performance; 39 return performance;
38 } 40 }
39 41
40 Widget build(Widget child) { 42 Widget build(Widget child) {
41 Widget current = child; 43 Widget current = child;
42 if (shadow != null || backgroundColor != null || 44 if (shadow != null || backgroundColor != null ||
43 borderRadius != null || shape != null) { 45 borderRadius != null || shape != null) {
44 current = new DecoratedBox( 46 current = new DecoratedBox(
45 decoration: new BoxDecoration( 47 decoration: new BoxDecoration(
46 borderRadius: borderRadius, 48 borderRadius: borderRadius,
47 shape: shape, 49 shape: shape,
48 boxShadow: shadow != null ? _computeShadow(shadow.value) : null, 50 boxShadow: shadow != null ? _computeShadow(shadow.value) : null,
49 backgroundColor: backgroundColor != null ? backgroundColor.value : nul l), 51 backgroundColor: backgroundColor != null ? backgroundColor.value : nul l),
50 child: current); 52 child: current);
51 } 53 }
52 54
53 if (position != null) { 55 if (position != null) {
54 Matrix4 transform = new Matrix4.identity(); 56 Matrix4 transform = new Matrix4.identity();
55 transform.translate(position.value.x, position.value.y); 57 transform.translate(position.value.x, position.value.y);
56 current = new Transform(transform: transform, child: child); 58 current = new Transform(transform: transform, child: current);
59 }
60
61 if (opacity != null) {
62 current = new Opacity(opacity: opacity.value, child: current);
57 } 63 }
58 64
59 return current; 65 return current;
60 } 66 }
61 67
62 void syncFields(AnimatedContainer source) { 68 void syncFields(AnimatedContainer source) {
63 _syncField(position, source.position); 69 _syncField(position, source.position);
64 _syncField(shadow, source.shadow); 70 _syncField(shadow, source.shadow);
65 _syncField(backgroundColor, source.backgroundColor); 71 _syncField(backgroundColor, source.backgroundColor);
66 72
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 112
107 int level1 = level.floor(); 113 int level1 = level.floor();
108 int level2 = level.ceil(); 114 int level2 = level.ceil();
109 double t = level - level1.toDouble(); 115 double t = level - level1.toDouble();
110 116
111 List<BoxShadow> shadow = new List<BoxShadow>(); 117 List<BoxShadow> shadow = new List<BoxShadow>();
112 for (int i = 0; i < shadows[level1].length; ++i) 118 for (int i = 0; i < shadows[level1].length; ++i)
113 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t)); 119 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t));
114 return shadow; 120 return shadow;
115 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698