diff --git a/sdk/lib/animation/animation_performance.dart b/sdk/lib/animation/animation_performance.dart index 9f13a3553ae..11c9822d71b 100644 --- a/sdk/lib/animation/animation_performance.dart +++ b/sdk/lib/animation/animation_performance.dart @@ -54,11 +54,16 @@ class AnimatedType extends AnimatedVariable { class AnimatedList extends AnimatedVariable { List variables; - AnimatedList(this.variables); + Interval interval; + + AnimatedList(this.variables, { this.interval }); + void setFraction(double t) { + double adjustedTime = interval == null ? t : interval.adjustTime(t); for (AnimatedVariable variable in variables) - variable.setFraction(t); + variable.setFraction(adjustedTime); } + String toString() => 'AnimatedList([$variables])'; } diff --git a/sdk/lib/widgets/popup_menu.dart b/sdk/lib/widgets/popup_menu.dart index b00fa3923f9..7b4641c1904 100644 --- a/sdk/lib/widgets/popup_menu.dart +++ b/sdk/lib/widgets/popup_menu.dart @@ -14,9 +14,8 @@ import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/popup_menu_item.dart'; import 'package:sky/widgets/scrollable_viewport.dart'; -const Duration _kMenuOpenDuration = const Duration(milliseconds: 300); -const Duration _kMenuCloseDuration = const Duration(milliseconds: 200); -const Duration _kMenuCloseDelay = const Duration(milliseconds: 100); +const Duration _kMenuDuration = const Duration(milliseconds: 300); +double _kMenuCloseIntervalEnd = 2.0 / 3.0; const double _kMenuWidthStep = 56.0; const double _kMenuMargin = 16.0; // 24.0 on tablet const double _kMenuMinWidth = 2.0 * _kMenuWidthStep; @@ -50,10 +49,12 @@ class PopupMenu extends AnimatedComponent { AnimatedType _width; AnimatedType _height; List> _itemOpacities; + AnimatedList _animationList; AnimationPerformance _performance; void initState() { _performance = new AnimationPerformance() + ..duration = _kMenuDuration ..addListener(_checkForStateChanged); _updateAnimationVariables(); watch(_performance); @@ -82,10 +83,10 @@ class PopupMenu extends AnimatedComponent { } void _updateAnimationVariables() { - double unit = 1.0 / (items.length + 1); + double unit = 1.0 / (items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade. _opacity = new AnimatedType(0.0, end: 1.0); _width = new AnimatedType(0.0, end: 1.0, interval: new Interval(0.0, unit)); - _height = new AnimatedType(0.0, end: 1.0, interval: new Interval(0.0, 0.5)); + _height = new AnimatedType(0.0, end: 1.0, interval: new Interval(0.0, unit * items.length)); _itemOpacities = new List>(); for (int i = 0; i < items.length; ++i) { double start = (i + 1) * unit; @@ -98,7 +99,8 @@ class PopupMenu extends AnimatedComponent { ..add(_width) ..add(_height) ..addAll(_itemOpacities); - _performance.variable = new AnimatedList(variables); + _animationList = new AnimatedList(variables); + _performance.variable = _animationList; } void _updateBoxPainter() { @@ -119,15 +121,13 @@ class PopupMenu extends AnimatedComponent { } void _open() { - _performance - ..duration = _kMenuOpenDuration - ..play(); + _animationList.interval = null; + _performance.play(); } void _close() { - _performance - ..duration = _kMenuCloseDuration - ..reverse(); + _animationList.interval = new Interval(0.0, _kMenuCloseIntervalEnd); + _performance.reverse(); } BoxPainter _painter;