fix(menu-toggle): fix race condition by checking for menu-toggle visibility after a menu registers with the menu-controller

This commit is contained in:
Dan Bucholtz
2018-02-23 09:49:14 -06:00
parent 7377590d16
commit 7694576068
4 changed files with 12 additions and 4 deletions

View File

@ -30,8 +30,9 @@ export class MenuToggle {
@Listen('body:ionMenuDisable') @Listen('body:ionMenuDisable')
@Listen('body:ionSplitPaneVisible') @Listen('body:ionSplitPaneVisible')
@Listen('body:ionMenuRegister')
updateVisibility() { updateVisibility() {
getMenuController().then(menuCtrl => { return getMenuController().then(menuCtrl => {
if (menuCtrl) { if (menuCtrl) {
const menu = menuCtrl.get(this.menu); const menu = menuCtrl.get(this.menu);
if (menu && menu.isActive()) { if (menu && menu.isActive()) {

View File

@ -40,13 +40,14 @@
<ion-content padding> <ion-content padding>
<ion-list> <ion-list>
<ion-menu-toggle>
<!-- <ion-menu-toggle> -->
<ion-item> <ion-item>
<ion-label> <ion-label>
List Item No Menu Toggle
</ion-label> </ion-label>
</ion-item> </ion-item>
</ion-menu-toggle> <!-- </ion-menu-toggle> -->
<ion-menu-toggle> <ion-menu-toggle>
<ion-item> <ion-item>

View File

@ -127,6 +127,8 @@ export class Menu {
@Event() protected ionMenuDisable: EventEmitter; @Event() protected ionMenuDisable: EventEmitter;
@Event() protected ionMenuRegister: EventEmitter;
componentWillLoad() { componentWillLoad() {
return this.lazyMenuCtrl.componentOnReady().then(menu => { return this.lazyMenuCtrl.componentOnReady().then(menu => {
this.menuCtrl = menu; this.menuCtrl = menu;
@ -163,6 +165,7 @@ export class Menu {
} }
// register this menu with the app's menu controller // register this menu with the app's menu controller
this.menuCtrl._register(this); this.menuCtrl._register(this);
this.ionMenuRegister.emit();
// mask it as enabled / disabled // mask it as enabled / disabled
this.disabled = !isEnabled; this.disabled = !isEnabled;

View File

@ -137,6 +137,9 @@ It reports the relative position.
#### ionMenuDisable #### ionMenuDisable
#### ionMenuRegister
#### ionOpen #### ionOpen
Emitted when the menu is open. Emitted when the menu is open.