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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « sky/framework/animation/animated_value.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 _kMenuCloseDuration = 200.0; 17 const double _kMenuCloseDuration = 200.0;
18 const double _kMenuCloseDelay = 100.0; 18 const double _kMenuCloseDelay = 100.0;
19 19
20 enum MenuState { Hidden, Opening, Open, Closing }
21
20 class PopupMenuController { 22 class PopupMenuController {
21 bool isOpen = false;
22 AnimatedValue position = new AnimatedValue(0.0); 23 AnimatedValue position = new AnimatedValue(0.0);
24 MenuState _state = MenuState.Hidden;
25 MenuState get state => _state;
23 26
24 void open() { 27 bool get canReact => (_state == MenuState.Opening) || (_state == MenuState.Ope n);
25 isOpen = true; 28
26 position.animateTo(1.0, _kMenuOpenDuration); 29 open() async {
30 if (_state != MenuState.Hidden)
31 return;
32 _state = MenuState.Opening;
33 if (await position.animateTo(1.0, _kMenuOpenDuration) == 1.0)
34 _state = MenuState.Open;
27 } 35 }
28 36
29 Future close() { 37 Future _closeState;
30 return position.animateTo(0.0, _kMenuCloseDuration, 38 close() async {
31 initialDelay: _kMenuCloseDelay).then((_) { 39 var result = new Completer();
32 isOpen = false; 40 _closeState = result.future;
33 }); 41 if ((_state == MenuState.Opening) || (_state == MenuState.Open)) {
42 _state = MenuState.Closing;
43 await position.animateTo(0.0, _kMenuCloseDuration, initialDelay: _kMenuClo seDelay);
44 _state = MenuState.Hidden;
45 _closeState = null;
46 result.complete();
47 return;
48 }
49 assert(_closeState != null);
50 return _closeState;
34 } 51 }
35 } 52 }
36 53
37 class PopupMenu extends AnimatedComponent { 54 class PopupMenu extends AnimatedComponent {
38 static final Style _style = new Style(''' 55 static final Style _style = new Style('''
39 border-radius: 2px; 56 border-radius: 2px;
40 padding: 8px 0; 57 padding: 8px 0;
41 box-sizing: border-box; 58 box-sizing: border-box;
42 background-color: ${Grey[50]};'''); 59 background-color: ${Grey[50]};''');
43 60
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 108
92 return new Material( 109 return new Material(
93 content: new Container( 110 content: new Container(
94 style: _style, 111 style: _style,
95 inlineStyle: _inlineStyle(), 112 inlineStyle: _inlineStyle(),
96 children: children 113 children: children
97 ), 114 ),
98 level: level); 115 level: level);
99 } 116 }
100 } 117 }
OLDNEW
« 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