Chromium Code Reviews| Index: sky/sdk/lib/widgets/popup_menu.dart |
| diff --git a/sky/sdk/lib/widgets/popup_menu.dart b/sky/sdk/lib/widgets/popup_menu.dart |
| index bf357eece3917eefdeef1d56a1781fbc1d208ba2..e2658dd6c362c761fa6464feac82221a9bf729d5 100644 |
| --- a/sky/sdk/lib/widgets/popup_menu.dart |
| +++ b/sky/sdk/lib/widgets/popup_menu.dart |
| @@ -6,7 +6,7 @@ import 'dart:async'; |
| import 'dart:math' as math; |
| import 'dart:sky' as sky; |
| -import '../animation/animated_value.dart'; |
| +import '../animation/animation_performance.dart'; |
| import '../painting/box_painter.dart'; |
| import '../theme/colors.dart'; |
| import '../theme/shadows.dart'; |
| @@ -14,9 +14,9 @@ import 'animated_component.dart'; |
| import 'basic.dart'; |
| import 'popup_menu_item.dart'; |
| -const double _kMenuOpenDuration = 300.0; |
| -const double _kMenuCloseDuration = 200.0; |
| -const double _kMenuCloseDelay = 100.0; |
| +const Duration _kMenuOpenDuration = const Duration(milliseconds: 300); |
| +const Duration _kMenuCloseDuration = const Duration(milliseconds: 200); |
| +const Duration _kMenuCloseDelay = const Duration(milliseconds: 100); |
| const double _kMenuWidthStep = 56.0; |
| const double _kMenuMargin = 16.0; // 24.0 on tablet |
| const double _kMenuMinWidth = 2.0 * _kMenuWidthStep; |
| @@ -24,37 +24,60 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep; |
| const double _kMenuHorizontalPadding = 16.0; |
| const double _kMenuVerticalPadding = 8.0; |
| -enum MenuState { hidden, opening, open, closing } |
| +enum MenuState { closed, opening, open, closing } |
| class PopupMenuController { |
| - AnimatedValue position = new AnimatedValue(0.0); |
| - MenuState _state = MenuState.hidden; |
| + |
| + PopupMenuController() { |
| + position = new AnimatedType<double>(0.0, end: 1.0); |
| + performance = new AnimationPerformance() |
| + ..variable = position |
| + ..addListener(_updateState); |
| + } |
| + |
| + AnimatedType<double> position; |
| + AnimationPerformance performance; |
| + |
| + MenuState _state = MenuState.closed; |
| MenuState get state => _state; |
|
Matt Perry
2015/07/10 00:32:17
This might be better if it were inferred from the
abarth-chromium
2015/07/10 02:42:11
Yeah, that's a good idea. Would it be ok to do th
|
| bool get canReact => (_state == MenuState.opening) || (_state == MenuState.open); |
| - open() async { |
| - if (_state != MenuState.hidden) |
| + void _updateState() { |
| + if (position.value == 0.0) { |
| + _state = MenuState.closed; |
| + if (_closeCompleter != null) { |
| + Completer localCompleter = _closeCompleter; |
| + _closeCompleter = null; |
| + localCompleter.complete(); |
| + } |
| return; |
| - _state = MenuState.opening; |
| - if (await position.animateTo(1.0, _kMenuOpenDuration) == 1.0) |
| + } |
| + |
| + if (position.value == 1.0) |
| _state = MenuState.open; |
| } |
| - Future _closeState; |
| - close() async { |
| - var result = new Completer(); |
| - _closeState = result.future; |
| - if ((_state == MenuState.opening) || (_state == MenuState.open)) { |
| - _state = MenuState.closing; |
| - await position.animateTo(0.0, _kMenuCloseDuration, initialDelay: _kMenuCloseDelay); |
| - _state = MenuState.hidden; |
| - _closeState = null; |
| - result.complete(); |
| - return result.future; |
| - } |
| - assert(_closeState != null); |
| - return _closeState; |
| + void open() { |
| + if (_state != MenuState.closed) |
| + return; |
| + _state = MenuState.opening; |
| + performance..duration = _kMenuOpenDuration |
| + ..play(); |
| + } |
| + |
| + Completer _closeCompleter; |
| + Future close() { |
| + if (_state == MenuState.closing || _state == MenuState.closed) |
| + return new Future.value(null); |
|
Matt Perry
2015/07/10 00:32:17
Do you mean to return _closeCompleter.future here?
abarth-chromium
2015/07/10 02:42:11
That's different from what the old code did, but t
|
| + |
| + _state = MenuState.closing; |
| + assert(_closeCompleter == null); |
| + _closeCompleter = new Completer(); |
| + performance |
| + ..duration = _kMenuCloseDuration |
| + ..reverse(delay: _kMenuCloseDelay); |
|
Matt Perry
2015/07/10 00:32:17
a timeout API would work here as long as we cancel
abarth-chromium
2015/07/10 02:42:11
If you'd prefer, I'm happy to switch this to a tim
|
| + return _closeCompleter.future; |
| } |
| } |
| @@ -66,7 +89,7 @@ class PopupMenu extends AnimatedComponent { |
| backgroundColor: Grey[50], |
| borderRadius: 2.0, |
| boxShadow: shadows[level])); |
| - watch(controller.position); |
| + watchPerformance(controller.performance); |
| } |
| PopupMenuController controller; |