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

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

Issue 1211603003: Baby steps towards an odeon-like animation system. First victim: Drawer. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: widget builder 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 '../base/lerp.dart';
6 import '../animation/animated_value.dart';
5 import '../painting/box_painter.dart'; 7 import '../painting/box_painter.dart';
6 import '../theme/colors.dart' as colors; 8 import '../theme/colors.dart' as colors;
7 import '../theme/edges.dart'; 9 import '../theme/edges.dart';
8 import '../theme/shadows.dart'; 10 import '../theme/shadows.dart';
11 import 'animated_component.dart';
9 import 'basic.dart'; 12 import 'basic.dart';
10 import 'default_text_style.dart'; 13 import 'default_text_style.dart';
11 import 'theme.dart'; 14 import 'theme.dart';
12 15
13 export '../theme/edges.dart' show MaterialEdge; 16 export '../theme/edges.dart' show MaterialEdge;
14 17
15 class Material extends Component { 18 const double _kAnimateShadowDurationMS = 100.0;
19
20 List<BoxShadow> computeShadow(double level) {
abarth-chromium 2015/06/30 22:26:09 We should probably name this function with an _ to
Matt Perry 2015/07/01 18:17:43 Done.
21 if (level < 1.0) // shadows[1] is the first shadow
22 return null;
23
24 int level1 = level.floor();
25 int level2 = level.ceil();
26 double t = level - level1.toDouble();
27
28 List<BoxShadow> shadow = new List<BoxShadow>();
29 for (int i = 0; i < shadows[level1].length; ++i)
30 shadow.add(BoxShadow.lerp(shadows[level1][i], shadows[level2][i], t));
31 return shadow;
32 }
33
34 class Material extends AnimatedComponent {
16 35
17 Material({ 36 Material({
18 String key, 37 String key,
19 this.child, 38 this.child,
20 this.edge: MaterialEdge.card, 39 this.edge: MaterialEdge.card,
21 this.level: 0, 40 int level: 0,
22 this.color 41 this.color
23 }) : super(key: key); 42 }) : super(key: key) {
43 this.level = new AnimatedValue(level.toDouble());
44 watch(this.level);
45 }
24 46
25 final Widget child; 47 Widget child;
26 final int level; 48 MaterialEdge edge;
27 final MaterialEdge edge; 49 AnimatedValue level;
28 final Color color; 50 Color color;
29 51
30 Color get backgroundColor { 52 Color get backgroundColor {
31 if (color != null) 53 if (color != null)
32 return color; 54 return color;
33 switch (Theme.of(this).brightness) { 55 switch (Theme.of(this).brightness) {
34 case ThemeBrightness.light: 56 case ThemeBrightness.light:
35 return colors.Grey[50]; 57 return colors.Grey[50];
36 case ThemeBrightness.dark: 58 case ThemeBrightness.dark:
37 return colors.Grey[850]; 59 return colors.Grey[850];
38 } 60 }
39 } 61 }
40 62
41 // TODO(ianh): we should make this animate level changes and color changes 63 void syncFields(Material source) {
64 child = source.child;
65 edge = source.edge;
66 // TODO(mpcomplete): duration is wrong, because the current level may be
67 // anything. We really want |rate|.
68 if (level.value != source.level.value)
69 level.animateTo(source.level.value.toDouble(), _kAnimateShadowDurationMS);
70 color = source.color;
71 super.syncFields(source);
72 }
73
74 // TODO(mpcomplete): make this animate color changes.
42 75
43 Widget build() { 76 Widget build() {
44 return new Container( 77 return new Container(
45 decoration: new BoxDecoration( 78 decoration: new BoxDecoration(
46 boxShadow: shadows[level], 79 boxShadow: computeShadow(level.value),
47 borderRadius: edges[edge], 80 borderRadius: edges[edge],
48 backgroundColor: backgroundColor, 81 backgroundColor: backgroundColor,
49 shape: edge == MaterialEdge.circle ? Shape.circle : Shape.rectangle 82 shape: edge == MaterialEdge.circle ? Shape.circle : Shape.rectangle
50 ), 83 ),
51 child: new DefaultTextStyle(style: Theme.of(this).text.body1, child: child ) 84 child: new DefaultTextStyle(style: Theme.of(this).text.body1, child: child )
52 ); 85 );
53 } 86 }
54 87
55 } 88 }
OLDNEW
« sky/sdk/lib/widgets/animated_component.dart ('K') | « sky/sdk/lib/widgets/drawer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698