| 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 'animated_component.dart'; | 5 import 'animated_component.dart'; |
| 6 import '../animation/animated_value.dart'; | 6 import '../animation/animated_value.dart'; |
| 7 import '../fn.dart'; | 7 import '../fn.dart'; |
| 8 import '../theme/colors.dart'; | 8 import '../theme/colors.dart'; |
| 9 import '../theme/view-configuration.dart'; | 9 import '../theme/view-configuration.dart'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:math' as math; | 11 import 'dart:math' as math; |
| 12 import 'dart:sky' as sky; | 12 import 'dart:sky' as sky; |
| 13 import 'material.dart'; | 13 import 'material.dart'; |
| 14 import 'popup_menu_item.dart'; | 14 import 'popup_menu_item.dart'; |
| 15 | 15 |
| 16 const double _kMenuOpenDuration = 300.0; | 16 const double _kMenuOpenDuration = 300.0; |
| 17 const double _kMenuCloneDuration = 200.0; | 17 const double _kMenuCloseDuration = 200.0; |
| 18 const double _kMenuCloseDelay = 100.0; |
| 18 | 19 |
| 19 class PopupMenuController { | 20 class PopupMenuController { |
| 20 bool isOpen = false; | 21 bool isOpen = false; |
| 21 AnimatedValue position = new AnimatedValue(0.0); | 22 AnimatedValue position = new AnimatedValue(0.0); |
| 22 | 23 |
| 23 void open() { | 24 void open() { |
| 24 isOpen = true; | 25 isOpen = true; |
| 25 position.animateTo(1.0, _kMenuOpenDuration); | 26 position.animateTo(1.0, _kMenuOpenDuration); |
| 26 } | 27 } |
| 27 | 28 |
| 28 Future close() { | 29 Future close() { |
| 29 return position.animateTo(0.0, _kMenuCloneDuration).then((_) { | 30 return position.animateTo(0.0, _kMenuCloseDuration, |
| 31 initialDelay: _kMenuCloseDelay).then((_) { |
| 30 isOpen = false; | 32 isOpen = false; |
| 31 }); | 33 }); |
| 32 } | 34 } |
| 33 } | 35 } |
| 34 | 36 |
| 35 class PopupMenu extends AnimatedComponent { | 37 class PopupMenu extends AnimatedComponent { |
| 36 static final Style _style = new Style(''' | 38 static final Style _style = new Style(''' |
| 37 border-radius: 2px; | 39 border-radius: 2px; |
| 38 padding: 8px 0; | 40 padding: 8px 0; |
| 39 box-sizing: border-box; | 41 box-sizing: border-box; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 }); | 82 }); |
| 81 } | 83 } |
| 82 | 84 |
| 83 Node build() { | 85 Node build() { |
| 84 int i = 0; | 86 int i = 0; |
| 85 List<Node> children = new List.from(items.map((List<Node> item) { | 87 List<Node> children = new List.from(items.map((List<Node> item) { |
| 86 double opacity = _opacityFor(i); | 88 double opacity = _opacityFor(i); |
| 87 return new PopupMenuItem(key: i++, children: item, opacity: opacity); | 89 return new PopupMenuItem(key: i++, children: item, opacity: opacity); |
| 88 })); | 90 })); |
| 89 | 91 |
| 90 return new StyleNode( | 92 return new Material( |
| 91 new Material( | 93 content: new Container( |
| 94 style: _style, |
| 92 inlineStyle: _inlineStyle(), | 95 inlineStyle: _inlineStyle(), |
| 93 children: children, | 96 children: children |
| 94 level: level), | 97 ), |
| 95 _style); | 98 level: level); |
| 96 } | 99 } |
| 97 } | 100 } |
| OLD | NEW |