| 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 '../fn.dart'; | 6 import '../fn.dart'; |
| 6 import '../theme/colors.dart'; | 7 import '../theme/colors.dart'; |
| 7 import 'material.dart'; | 8 import 'material.dart'; |
| 8 import 'popup_menu_item.dart'; | 9 import 'popup_menu_item.dart'; |
| 9 | 10 |
| 11 const double _kItemInitialOpacity = 0.0; |
| 12 const double _kItemFinalOpacity = 1.0; |
| 13 const double _kItemFadeDuration = 500.0; |
| 14 const double _kItemFadeDelay = 200.0; |
| 15 |
| 10 class PopupMenu extends Component { | 16 class PopupMenu extends Component { |
| 11 static final Style _style = new Style(''' | 17 static final Style _style = new Style(''' |
| 12 border-radius: 2px; | 18 border-radius: 2px; |
| 13 padding: 8px 0; | 19 padding: 8px 0; |
| 14 background-color: ${Grey[50]};''' | 20 background-color: ${Grey[50]};''' |
| 15 ); | 21 ); |
| 16 | 22 |
| 17 List<List<Node>> items; | 23 List<List<Node>> items; |
| 18 int level; | 24 int level; |
| 25 List<AnimatedValue> _opacities; |
| 19 | 26 |
| 20 PopupMenu({ Object key, this.items, this.level }) : super(key: key); | 27 PopupMenu({ Object key, this.items, this.level }) : super(key: key) { |
| 28 _opacities = new List.from(items.map( |
| 29 (item) => new AnimatedValue(_kItemInitialOpacity))); |
| 30 } |
| 31 |
| 32 // TODO(abarth): Rather than using didMount, we should have the parent |
| 33 // component kick off these animations. |
| 34 void didMount() { |
| 35 int i = 0; |
| 36 _opacities.forEach((opacity) { |
| 37 opacity.animateTo(_kItemFinalOpacity, _kItemFadeDuration, |
| 38 initialDelay: _kItemFadeDelay * i++); |
| 39 }); |
| 40 } |
| 21 | 41 |
| 22 Node build() { | 42 Node build() { |
| 23 List<Node> children = []; | 43 List<Node> children = []; |
| 24 int i = 0; | 44 int i = 0; |
| 25 items.forEach((List<Node> item) { | 45 items.forEach((List<Node> item) { |
| 26 children.add(new PopupMenuItem(key: i++, children: item)); | 46 children.add( |
| 47 new PopupMenuItem(key: i, children: item, opacity: _opacities[i])); |
| 48 ++i; |
| 27 }); | 49 }); |
| 28 | 50 |
| 29 return new Material( | 51 return new Material( |
| 30 style: _style, | 52 style: _style, |
| 31 children: children, | 53 children: children, |
| 32 level: level | 54 level: level |
| 33 ); | 55 ); |
| 34 } | 56 } |
| 35 } | 57 } |
| OLD | NEW |