Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/edges.dart'; | 8 import '../theme/edges.dart'; |
| 7 import '../theme/shadows.dart'; | 9 import '../theme/shadows.dart'; |
| 10 import 'animated_component.dart'; | |
| 8 import 'basic.dart'; | 11 import 'basic.dart'; |
| 9 import 'default_text_style.dart'; | 12 import 'default_text_style.dart'; |
| 10 import 'theme.dart'; | 13 import 'theme.dart'; |
| 11 | 14 |
| 12 export '../theme/edges.dart' show MaterialEdge; | 15 export '../theme/edges.dart' show MaterialEdge; |
| 13 | 16 |
| 14 class Material extends Component { | 17 const double _kAnimateShadowDurationMS = 100.0; |
| 18 | |
| 19 List<BoxShadow> computeShadow(double level) { | |
|
abarth-chromium
2015/07/01 19:44:09
s/computeShadow/_computeShadow/
Matt Perry
2015/07/01 20:05:40
Done.
| |
| 20 if (level < 1.0) // shadows[1] is the first shadow | |
| 21 return null; | |
| 22 | |
| 23 int level1 = level.floor(); | |
| 24 int level2 = level.ceil(); | |
| 25 double t = level - level1.toDouble(); | |
| 26 | |
| 27 List<BoxShadow> shadow = new List<BoxShadow>(); | |
| 28 for (int i = 0; i < shadows[level1].length; ++i) | |
| 29 shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t)); | |
| 30 return shadow; | |
| 31 } | |
| 32 | |
| 33 class Material extends AnimatedComponent { | |
| 15 | 34 |
| 16 Material({ | 35 Material({ |
| 17 String key, | 36 String key, |
| 18 this.child, | 37 this.child, |
| 19 this.edge: MaterialEdge.card, | 38 this.edge: MaterialEdge.card, |
| 20 this.level: 0, | 39 int level: 0, |
| 21 this.color | 40 this.color |
| 22 }) : super(key: key); | 41 }) : super(key: key) { |
| 42 this.level = new AnimatedValue(level.toDouble()); | |
| 43 watch(this.level); | |
| 44 } | |
| 23 | 45 |
| 24 final Widget child; | 46 Widget child; |
| 25 final int level; | 47 MaterialEdge edge; |
| 26 final MaterialEdge edge; | 48 AnimatedValue level; |
| 27 final Color color; | 49 Color color; |
| 28 | 50 |
| 29 // TODO(ianh): we should make this animate level changes and color changes | 51 void syncFields(Material source) { |
| 52 child = source.child; | |
| 53 edge = source.edge; | |
| 54 // TODO(mpcomplete): duration is wrong, because the current level may be | |
| 55 // anything. We really want |rate|. | |
| 56 if (level.value != source.level.value) | |
| 57 level.animateTo(source.level.value.toDouble(), _kAnimateShadowDurationMS); | |
| 58 color = source.color; | |
| 59 super.syncFields(source); | |
| 60 } | |
| 61 | |
| 62 // TODO(mpcomplete): make this animate color changes. | |
| 30 | 63 |
| 31 Widget build() { | 64 Widget build() { |
| 32 return new Container( | 65 return new Container( |
| 33 decoration: new BoxDecoration( | 66 decoration: new BoxDecoration( |
| 34 boxShadow: shadows[level], | 67 boxShadow: computeShadow(level.value), |
| 35 borderRadius: edges[edge], | 68 borderRadius: edges[edge], |
| 36 backgroundColor: color, | 69 backgroundColor: color, |
| 37 shape: edge == MaterialEdge.circle ? Shape.circle : Shape.rectangle | 70 shape: edge == MaterialEdge.circle ? Shape.circle : Shape.rectangle |
| 38 ), | 71 ), |
| 39 child: new DefaultTextStyle(style: Theme.of(this).text.body1, child: child ) | 72 child: new DefaultTextStyle(style: Theme.of(this).text.body1, child: child ) |
| 40 ); | 73 ); |
| 41 } | 74 } |
| 42 | 75 |
| 43 } | 76 } |
| OLD | NEW |