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

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

Issue 1224223004: Fix test failures from AnimatedContainer patch. (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
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/material.dart » ('j') | sky/sdk/lib/widgets/material.dart » ('J')
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 'package:vector_math/vector_math.dart'; 7 import 'package:vector_math/vector_math.dart';
8 8
9 import '../animation/animation_performance.dart'; 9 import '../animation/animation_performance.dart';
10 import '../animation/curves.dart'; 10 import '../animation/curves.dart';
11 import '../base/lerp.dart'; 11 import '../base/lerp.dart';
12 import '../painting/box_painter.dart'; 12 import '../painting/box_painter.dart';
13 import '../theme/shadows.dart'; 13 import '../theme/shadows.dart';
14 import 'basic.dart'; 14 import 'basic.dart';
15 15
16 // This class builds a Container object from a collection of optionally- 16 // This class builds a Container object from a collection of optionally-
17 // animated properties. Use syncFields to update the Container's properties, 17 // animated properties. Use syncFields to update the Container's properties,
18 // which will optionally animate them using an AnimationPerformance. 18 // which will optionally animate them using an AnimationPerformance.
19 class AnimatedContainer { 19 class AnimatedContainer {
20 AnimatedType<Point> position; 20 AnimatedType<Point> position;
21 AnimatedType<double> shadow; 21 AnimatedType<double> shadow;
22 AnimatedColor backgroundColor; 22 AnimatedColor backgroundColor;
23 23
24 // These don't animate, but are used to build the Container anyway.
25 double borderRadius;
26 Shape shape;
27
24 Map<AnimatedVariable, AnimationPerformance> _variableToPerformance = 28 Map<AnimatedVariable, AnimationPerformance> _variableToPerformance =
25 new Map<AnimatedVariable, AnimationPerformance>(); 29 new Map<AnimatedVariable, AnimationPerformance>();
26 30
27 AnimatedContainer(); 31 AnimatedContainer();
28 32
29 AnimationPerformance createPerformance(AnimatedType variable, 33 AnimationPerformance createPerformance(AnimatedType variable,
30 {Duration duration}) { 34 {Duration duration}) {
31 AnimationPerformance performance = new AnimationPerformance() 35 AnimationPerformance performance = new AnimationPerformance()
32 ..duration = duration 36 ..duration = duration
33 ..variable = variable; 37 ..variable = variable;
34 _variableToPerformance[variable] = performance; 38 _variableToPerformance[variable] = performance;
35 return performance; 39 return performance;
36 } 40 }
37 41
38 Widget build(Widget child) { 42 Widget build(Widget child) {
39 Widget current = child; 43 Widget current = child;
40 if (shadow != null || backgroundColor != null) { 44 if (shadow != null || backgroundColor != null ||
45 borderRadius != null || shape != null) {
41 current = new DecoratedBox( 46 current = new DecoratedBox(
42 decoration: new BoxDecoration( 47 decoration: new BoxDecoration(
48 borderRadius: borderRadius,
49 shape: shape,
43 boxShadow: shadow != null ? _computeShadow(shadow.value) : null, 50 boxShadow: shadow != null ? _computeShadow(shadow.value) : null,
44 backgroundColor: backgroundColor != null ? backgroundColor.value : nul l), 51 backgroundColor: backgroundColor != null ? backgroundColor.value : nul l),
45 child: current); 52 child: current);
46 } 53 }
47 54
48 if (position != null) { 55 if (position != null) {
49 Matrix4 transform = new Matrix4.identity(); 56 Matrix4 transform = new Matrix4.identity();
50 transform.translate(position.value.x, position.value.y); 57 transform.translate(position.value.x, position.value.y);
51 current = new Transform(transform: transform, child: child); 58 current = new Transform(transform: transform, child: child);
52 } 59 }
53 60
54 return current; 61 return current;
55 } 62 }
56 63
57 void syncFields(AnimatedContainer source) { 64 void syncFields(AnimatedContainer source) {
58 _syncField(position, source.position); 65 _syncField(position, source.position);
59 _syncField(shadow, source.shadow); 66 _syncField(shadow, source.shadow);
60 _syncField(backgroundColor, source.backgroundColor); 67 _syncField(backgroundColor, source.backgroundColor);
68
69 borderRadius = source.borderRadius;
70 shape = source.shape;
61 } 71 }
62 72
63 void _syncField(AnimatedType variable, AnimatedType sourceVariable) { 73 void _syncField(AnimatedType variable, AnimatedType sourceVariable) {
64 if (variable == null) 74 if (variable == null)
65 return; // TODO(mpcomplete): Should we handle transition from null? 75 return; // TODO(mpcomplete): Should we handle transition from null?
66 76
67 AnimationPerformance performance = _variableToPerformance[variable]; 77 AnimationPerformance performance = _variableToPerformance[variable];
68 if (performance == null) { 78 if (performance == null) {
69 // If there's no performance, no need to animate. 79 // If there's no performance, no need to animate.
70 if (sourceVariable != null) 80 if (sourceVariable != null)
(...skipping 27 matching lines...) Expand all
98 108
99 int level1 = level.floor(); 109 int level1 = level.floor();
100 int level2 = level.ceil(); 110 int level2 = level.ceil();
101 double t = level - level1.toDouble(); 111 double t = level - level1.toDouble();
102 112
103 List<BoxShadow> shadow = new List<BoxShadow>(); 113 List<BoxShadow> shadow = new List<BoxShadow>();
104 for (int i = 0; i < shadows[level1].length; ++i) 114 for (int i = 0; i < shadows[level1].length; ++i)
105 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t)); 115 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t));
106 return shadow; 116 return shadow;
107 } 117 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/material.dart » ('j') | sky/sdk/lib/widgets/material.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698