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

Unified Diff: sky/framework/components/popup_menu.dart

Issue 1074883005: [Effen] Tapping on a menu while it's closing should not make it instantly disappear. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix enum case Created 5 years, 8 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
« no previous file with comments | « sky/framework/animation/animated_value.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/components/popup_menu.dart
diff --git a/sky/framework/components/popup_menu.dart b/sky/framework/components/popup_menu.dart
index 19b47df14e689236a287efb5e85f7917eef6c6ca..e91a4301f43e4df85d14fc627b2477a8ccb3b5f7 100644
--- a/sky/framework/components/popup_menu.dart
+++ b/sky/framework/components/popup_menu.dart
@@ -17,20 +17,37 @@ const double _kMenuOpenDuration = 300.0;
const double _kMenuCloseDuration = 200.0;
const double _kMenuCloseDelay = 100.0;
+enum MenuState { Hidden, Opening, Open, Closing }
+
class PopupMenuController {
- bool isOpen = false;
AnimatedValue position = new AnimatedValue(0.0);
+ MenuState _state = MenuState.Hidden;
+ MenuState get state => _state;
+
+ bool get canReact => (_state == MenuState.Opening) || (_state == MenuState.Open);
- void open() {
- isOpen = true;
- position.animateTo(1.0, _kMenuOpenDuration);
+ open() async {
+ if (_state != MenuState.Hidden)
+ return;
+ _state = MenuState.Opening;
+ if (await position.animateTo(1.0, _kMenuOpenDuration) == 1.0)
+ _state = MenuState.Open;
}
- Future close() {
- return position.animateTo(0.0, _kMenuCloseDuration,
- initialDelay: _kMenuCloseDelay).then((_) {
- isOpen = false;
- });
+ 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;
+ }
+ assert(_closeState != null);
+ return _closeState;
}
}
« no previous file with comments | « sky/framework/animation/animated_value.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698