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 '../animation/animated_value.dart'; | 5 import '../animation/animated_value.dart'; |
| 6 import '../animation/animation_performance.dart'; | 6 import '../animation/animation_performance.dart'; |
| 7 import '../painting/box_painter.dart'; | 7 import '../painting/box_painter.dart'; |
| 8 import '../theme/shadows.dart'; | 8 import '../theme/shadows.dart'; |
| 9 import 'animated_component.dart'; | 9 import 'animated_component.dart'; |
| 10 import 'animated_container.dart'; | 10 import 'animated_container.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 const Duration _kAnimateShadowDuration = const Duration(milliseconds: 100); | 24 const Duration _kAnimateShadowDuration = const Duration(milliseconds: 100); |
| 25 const Duration _kAnimateColorDuration = const Duration(milliseconds: 100); | 25 const Duration _kAnimateColorDuration = const Duration(milliseconds: 100); |
| 26 | 26 |
| 27 class Material extends AnimatedComponent { | 27 class Material extends AnimatedComponent { |
| 28 | 28 |
| 29 Material({ | 29 Material({ |
| 30 String key, | 30 String key, |
| 31 this.child, | 31 this.child, |
| 32 this.type: MaterialType.card, | 32 MaterialType type: MaterialType.card, |
| 33 int level: 0, | 33 int level: 0, |
| 34 Color color: null | 34 Color color: null |
| 35 }) : super(key: key) { | 35 }) : super(key: key) { |
| 36 if (level == null) level = 0; | 36 if (level == null) level = 0; |
| 37 _container = new AnimatedContainer() | 37 _container = new AnimatedContainer() |
| 38 ..shadow = new AnimatedType<double>(level.toDouble()) | 38 ..shadow = new AnimatedType<double>(level.toDouble()) |
| 39 ..backgroundColor = new AnimatedColor(_getBackgroundColor(color)); | 39 ..backgroundColor = new AnimatedColor(_getBackgroundColor(type, color)) |
|
Matt Perry
2015/07/09 19:17:21
One thing I'm worried about here: do we create a n
abarth-chromium
2015/07/09 19:19:00
We create a new widget.
| |
| 40 ..borderRadius = edges[type] | |
| 41 ..shape = type == MaterialType.circle ? Shape.circle : Shape.rectangle; | |
| 40 watch(_container.createPerformance( | 42 watch(_container.createPerformance( |
| 41 _container.shadow, duration: _kAnimateShadowDuration).timeline); | 43 _container.shadow, duration: _kAnimateShadowDuration).timeline); |
| 42 watch(_container.createPerformance( | 44 watch(_container.createPerformance( |
| 43 _container.backgroundColor, duration: _kAnimateColorDuration).timeline); | 45 _container.backgroundColor, duration: _kAnimateColorDuration).timeline); |
| 44 } | 46 } |
| 45 | 47 |
| 46 Widget child; | 48 Widget child; |
| 47 MaterialType type; | |
| 48 | 49 |
| 49 AnimatedContainer _container; | 50 AnimatedContainer _container; |
| 50 | 51 |
| 51 void syncFields(Material source) { | 52 void syncFields(Material source) { |
| 52 child = source.child; | 53 child = source.child; |
| 53 type = source.type; | |
| 54 _container.syncFields(source._container); | 54 _container.syncFields(source._container); |
| 55 super.syncFields(source); | 55 super.syncFields(source); |
| 56 } | 56 } |
| 57 | 57 |
| 58 Color _getBackgroundColor(Color color) { | 58 Color _getBackgroundColor(MaterialType type, Color color) { |
| 59 if (color != null) | 59 if (color != null) |
| 60 return color; | 60 return color; |
| 61 switch(type) { | 61 switch (type) { |
| 62 case MaterialType.canvas: | 62 case MaterialType.canvas: |
| 63 return Theme.of(this).canvasColor; | 63 return Theme.of(this).canvasColor; |
| 64 case MaterialType.card: | 64 case MaterialType.card: |
| 65 return Theme.of(this).cardColor; | 65 return Theme.of(this).cardColor; |
| 66 default: | 66 default: |
| 67 return null; | 67 return null; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 Widget build() { | 71 Widget build() { |
| 72 return _container.build( | 72 return _container.build( |
| 73 new Container( | 73 new DefaultTextStyle(style: Theme.of(this).text.body1, child: child) |
| 74 // TODO(mpcomplete): move the rest of this decoration into | 74 ); |
| 75 // AnimatedContainer as non-animated values. | |
| 76 decoration: new BoxDecoration( | |
| 77 borderRadius: edges[type], | |
| 78 shape: type == MaterialType.circle ? Shape.circle : Shape.rectangle | |
| 79 ), | |
| 80 child: new DefaultTextStyle(style: Theme.of(this).text.body1, child: chi ld) | |
| 81 )); | |
| 82 } | 75 } |
| 83 | 76 |
| 84 } | 77 } |
| OLD | NEW |