Skip to content

Commit 1e95e85

Browse files
committed
fix(menu): two menus can’t be animated at the same time
1 parent c6facf3 commit 1e95e85

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/components/menu/menu-controller.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export class MenuController {
125125
* @return {Promise} returns a promise when the menu is fully opened
126126
*/
127127
open(menuId?: string): Promise<boolean> {
128-
let menu = this.get(menuId);
129-
if (menu) {
128+
const menu = this.get(menuId);
129+
if (menu && !this.isAnimating()) {
130130
let openedMenu = this.getOpen();
131131
if (openedMenu && menu !== openedMenu) {
132132
openedMenu.setOpen(false, false);
@@ -171,9 +171,9 @@ export class MenuController {
171171
* @return {Promise} returns a promise when the menu has been toggled
172172
*/
173173
toggle(menuId?: string): Promise<boolean> {
174-
let menu = this.get(menuId);
175-
if (menu) {
176-
let openedMenu = this.getOpen();
174+
const menu = this.get(menuId);
175+
if (menu && !this.isAnimating()) {
176+
var openedMenu = this.getOpen();
177177
if (openedMenu && menu !== openedMenu) {
178178
openedMenu.setOpen(false, false);
179179
}
@@ -191,7 +191,7 @@ export class MenuController {
191191
* @return {Menu} Returns the instance of the menu, which is useful for chaining.
192192
*/
193193
enable(shouldEnable: boolean, menuId?: string): Menu {
194-
let menu = this.get(menuId);
194+
const menu = this.get(menuId);
195195
if (menu) {
196196
return menu.enable(shouldEnable);
197197
}
@@ -204,7 +204,7 @@ export class MenuController {
204204
* @return {Menu} Returns the instance of the menu, which is useful for chaining.
205205
*/
206206
swipeEnable(shouldEnable: boolean, menuId?: string): Menu {
207-
let menu = this.get(menuId);
207+
const menu = this.get(menuId);
208208
if (menu) {
209209
return menu.swipeEnable(shouldEnable);
210210
}
@@ -229,7 +229,7 @@ export class MenuController {
229229
* @return {boolean} Returns true if the menu is currently enabled, otherwise false.
230230
*/
231231
isEnabled(menuId?: string): boolean {
232-
let menu = this.get(menuId);
232+
const menu = this.get(menuId);
233233
return menu && menu.enabled || false;
234234
}
235235

@@ -278,14 +278,21 @@ export class MenuController {
278278
return this._menus.find(m => m.isOpen);
279279
}
280280

281-
282281
/**
283282
* @return {Array<Menu>} Returns an array of all menu instances.
284283
*/
285284
getMenus(): Array<Menu> {
286285
return this._menus;
287286
}
288287

288+
/**
289+
* @private
290+
* @return {boolean} if any menu is currently animating
291+
*/
292+
isAnimating(): boolean {
293+
return this._menus.some(menu => menu.isAnimating());
294+
}
295+
289296
/**
290297
* @private
291298
*/

src/components/menu/menu.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export class Menu {
412412
setOpen(shouldOpen: boolean, animated: boolean = true): Promise<boolean> {
413413
// _isPrevented is used to prevent unwanted opening/closing after swiping open/close
414414
// or swiping open the menu while pressing down on the MenuToggle button
415-
if ((shouldOpen && this.isOpen) || !this._isEnabled || this._isAnimating) {
415+
if ((shouldOpen === this.isOpen) || !this._isEnabled || this._isAnimating) {
416416
return Promise.resolve(this.isOpen);
417417
}
418418

@@ -436,6 +436,13 @@ export class Menu {
436436
this._app.isEnabled();
437437
}
438438

439+
/**
440+
* @private
441+
*/
442+
isAnimating(): boolean {
443+
return this._isAnimating;
444+
}
445+
439446
_swipeBeforeStart() {
440447
if (!this.canSwipe()) {
441448
assert(false, 'canSwipe() has to be true');

0 commit comments

Comments
 (0)