feat(menu): allow persistent menus

Closes #5204
This commit is contained in:
Adam Bradley
2016-02-15 21:40:16 -06:00
parent c02fb51d04
commit 0d47a1b79f
5 changed files with 52 additions and 9 deletions

View File

@ -120,7 +120,25 @@ import {MenuType} from './menu-types';
* but this can be overriden using the `type` property: * but this can be overriden using the `type` property:
* *
* ```html * ```html
* <ion-menu type="overlay" [content]="mycontent"></ion-menu> * <ion-menu type="overlay" [content]="mycontent">...</ion-menu>
* ```
*
*
* ### Persistent Menus
*
* By default, menus, and specifically their menu toggle buttons in the navbar,
* only show on the root page within its `NavController`. For example, on Page 1
* the menu toggle will show in the navbar. However, when navigating to Page 2,
* because it is not the root Page for that `NavController`, the menu toggle
* will not show in the navbar.
*
* Not showing the menu toggle button in the navbar is commonly seen within
* native apps after navigating past the root Page. However, it is still possible
* to always show the menu toggle button in the navbar by setting
* `persistent="true"` on the `ion-menu` component.
*
* ```html
* <ion-menu persistent="true" [content]="content">...</ion-menu>
* ``` * ```
* *
* @demo /docs/v2/demos/menu/ * @demo /docs/v2/demos/menu/

View File

@ -68,7 +68,17 @@ export class MenuToggle {
*/ */
get isHidden() { get isHidden() {
if (this._inNavbar && this._viewCtrl) { if (this._inNavbar && this._viewCtrl) {
return !this._viewCtrl.isRoot(); if (this._viewCtrl.isRoot()) {
// this is the root view, so it should always show
return false;
}
let menu = this._menu.get(this.menuToggle);
if (menu) {
// this is not the root view, so see if this menu
// is configured to still be enabled if it's not the root view
return !menu.persistent;
}
} }
return false; return false;
} }

View File

@ -5,7 +5,6 @@ import {Config} from '../../config/config';
import {Platform} from '../../platform/platform'; import {Platform} from '../../platform/platform';
import {Keyboard} from '../../util/keyboard'; import {Keyboard} from '../../util/keyboard';
import {MenuContentGesture, MenuTargetGesture} from './menu-gestures'; import {MenuContentGesture, MenuTargetGesture} from './menu-gestures';
import {Gesture} from '../../gestures/gesture';
import {MenuController} from './menu-controller'; import {MenuController} from './menu-controller';
import {MenuType} from './menu-types'; import {MenuType} from './menu-types';
import {isTrueProperty} from '../../util/util'; import {isTrueProperty} from '../../util/util';
@ -27,13 +26,14 @@ import {isTrueProperty} from '../../util/util';
export class Menu extends Ion { export class Menu extends Ion {
private _preventTime: number = 0; private _preventTime: number = 0;
private _cntEle: HTMLElement; private _cntEle: HTMLElement;
private _cntGesture: Gesture; private _cntGesture: MenuTargetGesture;
private _menuGesture: Gesture; private _menuGesture: MenuContentGesture;
private _type: MenuType; private _type: MenuType;
private _resizeUnreg: Function; private _resizeUnreg: Function;
private _isEnabled: boolean = true; private _isEnabled: boolean = true;
private _isSwipeEnabled: boolean = true; private _isSwipeEnabled: boolean = true;
private _isListening: boolean = false; private _isListening: boolean = false;
private _isPers: boolean = false;
private _init: boolean = false; private _init: boolean = false;
/** /**
@ -51,7 +51,6 @@ export class Menu extends Ion {
*/ */
onContentClick: EventListener; onContentClick: EventListener;
/** /**
* @private * @private
*/ */
@ -101,12 +100,24 @@ export class Menu extends Ion {
/** /**
* @private * @private
*/ */
@Input() maxEdgeStart; @Input()
get persistent(): boolean {
return this._isPers;
}
set persistent(val: boolean) {
this._isPers = isTrueProperty(val);
}
/** /**
* @private * @private
*/ */
@Output() opening: EventEmitter<any> = new EventEmitter(); @Input() maxEdgeStart: number;
/**
* @private
*/
@Output() opening: EventEmitter<number> = new EventEmitter();
constructor( constructor(
private _menuCtrl: MenuController, private _menuCtrl: MenuController,

View File

@ -1,4 +1,4 @@
<ion-menu [content]="content" side="left"> <ion-menu [content]="content" side="left" persistent="true">
<ion-toolbar secondary> <ion-toolbar secondary>
<ion-title>Left Menu</ion-title> <ion-title>Left Menu</ion-title>

View File

@ -1,6 +1,10 @@
<ion-navbar *navbar> <ion-navbar *navbar>
<button menuToggle="left">
<ion-icon name="menu"></ion-icon>
</button>
<ion-title> <ion-title>
Menu Menu
</ion-title> </ion-title>