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

Side by Side Diff: sky/sdk/lib/widgets/material.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 | « sky/sdk/lib/widgets/animated_container.dart ('k') | sky/tests/examples/sector-expected.txt » ('j') | 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 '../animation/animation_performance.dart'; 5 import '../animation/animation_performance.dart';
6 import '../painting/box_painter.dart'; 6 import '../painting/box_painter.dart';
7 import 'animated_component.dart'; 7 import 'animated_component.dart';
8 import 'animated_container.dart'; 8 import 'animated_container.dart';
9 import 'basic.dart'; 9 import 'basic.dart';
10 import 'default_text_style.dart'; 10 import 'default_text_style.dart';
11 import 'theme.dart'; 11 import 'theme.dart';
12 12
13 enum MaterialType { canvas, card, circle, button } 13 enum MaterialType { canvas, card, circle, button }
14 14
15 const Map<MaterialType, double> edges = const { 15 const Map<MaterialType, double> edges = const {
16 MaterialType.canvas: null, 16 MaterialType.canvas: null,
17 MaterialType.card: 2.0, 17 MaterialType.card: 2.0,
18 MaterialType.circle: null, 18 MaterialType.circle: null,
19 MaterialType.button: 2.0, 19 MaterialType.button: 2.0,
20 }; 20 };
21 21
22 const Duration _kAnimateShadowDuration = const Duration(milliseconds: 100); 22 const Duration _kAnimateShadowDuration = const Duration(milliseconds: 100);
23 const Duration _kAnimateColorDuration = const Duration(milliseconds: 100); 23 const Duration _kAnimateColorDuration = const Duration(milliseconds: 100);
24 24
25 class Material extends AnimatedComponent { 25 class Material extends AnimatedComponent {
26 26
27 Material({ 27 Material({
28 String key, 28 String key,
29 this.child, 29 this.child,
30 this.type: MaterialType.card, 30 MaterialType type: MaterialType.card,
31 int level: 0, 31 int level: 0,
32 Color color: null 32 Color color: null
33 }) : super(key: key) { 33 }) : super(key: key) {
34 if (level == null) level = 0; 34 if (level == null) level = 0;
Hixie 2015/07/09 20:58:40 This constructor is getting out of control. Widget
Matt Perry 2015/07/09 21:03:13 Is there a method that gets called after construct
35 _container = new AnimatedContainer() 35 _container = new AnimatedContainer()
36 ..shadow = new AnimatedType<double>(level.toDouble()) 36 ..shadow = new AnimatedType<double>(level.toDouble())
37 ..backgroundColor = new AnimatedColor(_getBackgroundColor(color)); 37 ..backgroundColor = new AnimatedColor(_getBackgroundColor(type, color))
38 ..borderRadius = edges[type]
39 ..shape = type == MaterialType.circle ? Shape.circle : Shape.rectangle;
38 watchPerformance(_container.createPerformance( 40 watchPerformance(_container.createPerformance(
39 _container.shadow, duration: _kAnimateShadowDuration)); 41 _container.shadow, duration: _kAnimateShadowDuration));
40 watchPerformance(_container.createPerformance( 42 watchPerformance(_container.createPerformance(
41 _container.backgroundColor, duration: _kAnimateColorDuration)); 43 _container.backgroundColor, duration: _kAnimateColorDuration));
42 } 44 }
43 45
44 Widget child; 46 Widget child;
45 MaterialType type;
46 47
47 AnimatedContainer _container; 48 AnimatedContainer _container;
48 49
49 void syncFields(Material source) { 50 void syncFields(Material source) {
50 child = source.child; 51 child = source.child;
51 type = source.type;
52 _container.syncFields(source._container); 52 _container.syncFields(source._container);
53 super.syncFields(source); 53 super.syncFields(source);
54 } 54 }
55 55
56 Color _getBackgroundColor(Color color) { 56 Color _getBackgroundColor(MaterialType type, Color color) {
57 if (color != null) 57 if (color != null)
58 return color; 58 return color;
59 switch(type) { 59 switch (type) {
60 case MaterialType.canvas: 60 case MaterialType.canvas:
61 return Theme.of(this).canvasColor; 61 return Theme.of(this).canvasColor;
62 case MaterialType.card: 62 case MaterialType.card:
63 return Theme.of(this).cardColor; 63 return Theme.of(this).cardColor;
64 default: 64 default:
65 return null; 65 return null;
66 } 66 }
67 } 67 }
68 68
69 Widget build() { 69 Widget build() {
70 return _container.build( 70 return _container.build(
71 new Container( 71 new DefaultTextStyle(style: Theme.of(this).text.body1, child: child)
72 // TODO(mpcomplete): move the rest of this decoration into 72 );
73 // AnimatedContainer as non-animated values.
74 decoration: new BoxDecoration(
75 borderRadius: edges[type],
76 shape: type == MaterialType.circle ? Shape.circle : Shape.rectangle
77 ),
78 child: new DefaultTextStyle(style: Theme.of(this).text.body1, child: chi ld)
79 ));
80 } 73 }
81 74
82 } 75 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/animated_container.dart ('k') | sky/tests/examples/sector-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698