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

Unified 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: better lerp Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« sky/sdk/lib/widgets/drawer.dart ('K') | « sky/sdk/lib/widgets/drawer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/material.dart
diff --git a/sky/sdk/lib/widgets/material.dart b/sky/sdk/lib/widgets/material.dart
index 527e055bde83a96951d3e262e55f0aa86ed23c13..9304e9e862af4a1a4151e4f7ba27b56635e8e17b 100644
--- a/sky/sdk/lib/widgets/material.dart
+++ b/sky/sdk/lib/widgets/material.dart
@@ -2,30 +2,52 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import '../base/lerp.dart';
+import '../animation/animated_value.dart';
import '../painting/box_painter.dart';
import '../theme/colors.dart' as colors;
import '../theme/edges.dart';
import '../theme/shadows.dart';
+import 'animated_component.dart';
import 'basic.dart';
import 'default_text_style.dart';
import 'theme.dart';
export '../theme/edges.dart' show MaterialEdge;
-class Material extends Component {
+const double _kAnimateShadowDurationMS = 100.0;
+
+List<BoxShadow> computeShadow(double level) {
+ if (level < 1.0) // shadows[1] is the first shadow
+ return null;
+
+ int level1 = level.floor();
+ int level2 = level.ceil();
+ double t = level - level1.toDouble();
+
+ List<BoxShadow> shadow = new List<BoxShadow>();
+ for (int i = 0; i < shadows[level1].length; ++i)
+ shadow.add(BoxShadow.lerp(shadows[level1][i], shadows[level2][i], t));
+ return shadow;
+}
+
+class Material extends AnimatedComponent {
Material({
String key,
this.child,
this.edge: MaterialEdge.card,
- this.level: 0,
+ int level: 0,
this.color
- }) : super(key: key);
+ }) : super(key: key) {
+ this.level = new AnimatedValue(level.toDouble());
+ watch(this.level);
+ }
- final Widget child;
- final int level;
- final MaterialEdge edge;
- final Color color;
+ Widget child;
+ MaterialEdge edge;
+ AnimatedValue level;
+ Color color;
Color get backgroundColor {
if (color != null)
@@ -38,12 +60,23 @@ class Material extends Component {
}
}
- // TODO(ianh): we should make this animate level changes and color changes
+ void syncFields(Material source) {
+ child = source.child;
+ edge = source.edge;
+ // TODO(mpcomplete): duration is wrong, because the current level may be
+ // anything. We really want |rate|.
+ if (level.value != source.level.value)
+ level.animateTo(source.level.value.toDouble(), _kAnimateShadowDurationMS);
+ color = source.color;
+ super.syncFields(source);
+ }
+
+ // TODO(mpcomplete): make this animate color changes.
Widget build() {
return new Container(
decoration: new BoxDecoration(
- boxShadow: shadows[level],
+ boxShadow: computeShadow(level.value),
borderRadius: edges[edge],
backgroundColor: backgroundColor,
shape: edge == MaterialEdge.circle ? Shape.circle : Shape.rectangle
« sky/sdk/lib/widgets/drawer.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