mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 21:48:42 +08:00
perf(menu): several improvements
- `display: none;` when menu is closed - `ion-backdrop` is display: none when it is not used - `ion-backdrop` is much smaller
This commit is contained in:

committed by
Adam Bradley

parent
ba53a23c6e
commit
86c5aaf7a1
@ -8,7 +8,7 @@ $menu-ios-box-shadow-color: rgba(0, 0, 0, .25) !default;
|
|||||||
$menu-ios-box-shadow: 0 0 10px $menu-ios-box-shadow-color !default;
|
$menu-ios-box-shadow: 0 0 10px $menu-ios-box-shadow-color !default;
|
||||||
|
|
||||||
|
|
||||||
ion-menu {
|
.menu-inner {
|
||||||
background: $menu-ios-background;
|
background: $menu-ios-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +20,6 @@ ion-menu {
|
|||||||
box-shadow: $menu-ios-box-shadow;
|
box-shadow: $menu-ios-box-shadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-menu[type=overlay] {
|
ion-menu[type=overlay] .menu-inner {
|
||||||
box-shadow: $menu-ios-box-shadow;
|
box-shadow: $menu-ios-box-shadow;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ $menu-md-box-shadow-color: rgba(0, 0, 0, .25) !default;
|
|||||||
$menu-md-box-shadow: 0 0 10px $menu-md-box-shadow-color !default;
|
$menu-md-box-shadow: 0 0 10px $menu-md-box-shadow-color !default;
|
||||||
|
|
||||||
|
|
||||||
ion-menu {
|
.menu-inner {
|
||||||
background: $menu-md-background;
|
background: $menu-md-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +20,6 @@ ion-menu {
|
|||||||
box-shadow: $menu-md-box-shadow;
|
box-shadow: $menu-md-box-shadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-menu[type=overlay] {
|
ion-menu[type=overlay] .menu-inner {
|
||||||
box-shadow: $menu-md-box-shadow;
|
box-shadow: $menu-md-box-shadow;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,21 @@ $menu-small-width: $menu-width - 40px !default;
|
|||||||
|
|
||||||
|
|
||||||
ion-menu {
|
ion-menu {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
&.show-menu {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.menu-inner {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: auto;
|
right: auto;
|
||||||
@ -23,13 +38,13 @@ ion-menu {
|
|||||||
transform: translate3d(-9999px, 0, 0);
|
transform: translate3d(-9999px, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-menu > ion-header,
|
.menu-inner > ion-header,
|
||||||
ion-menu > ion-content,
|
.menu-inner > ion-content,
|
||||||
ion-menu > ion-footer {
|
.menu-inner > ion-footer {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-menu[side=right] {
|
ion-menu[side=right] > .menu-inner {
|
||||||
right: 0;
|
right: 0;
|
||||||
left: auto;
|
left: auto;
|
||||||
}
|
}
|
||||||
@ -37,6 +52,8 @@ ion-menu[side=right] {
|
|||||||
ion-menu ion-backdrop {
|
ion-menu ion-backdrop {
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
display: none;
|
display: none;
|
||||||
|
|
||||||
|
opacity: .1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-content {
|
.menu-content {
|
||||||
@ -54,7 +71,7 @@ ion-menu ion-backdrop {
|
|||||||
|
|
||||||
@media (max-width: 340px) {
|
@media (max-width: 340px) {
|
||||||
|
|
||||||
ion-menu {
|
.menu-inner {
|
||||||
width: $menu-small-width;
|
width: $menu-small-width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +83,11 @@ ion-menu ion-backdrop {
|
|||||||
// The content slides over to reveal the menu underneath.
|
// The content slides over to reveal the menu underneath.
|
||||||
// The menu itself, which is under the content, does not move.
|
// The menu itself, which is under the content, does not move.
|
||||||
|
|
||||||
ion-menu[type=reveal].show-menu {
|
ion-menu[type=reveal] {
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ion-menu[type=reveal].show-menu .menu-inner {
|
||||||
transform: translate3d(0, 0, 0);
|
transform: translate3d(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,17 +100,7 @@ ion-menu[type=reveal].show-menu {
|
|||||||
ion-menu[type=overlay] {
|
ion-menu[type=overlay] {
|
||||||
z-index: $z-index-menu-overlay;
|
z-index: $z-index-menu-overlay;
|
||||||
|
|
||||||
ion-backdrop {
|
.show-backdrop {
|
||||||
left: -3000px;
|
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
width: 6000px;
|
|
||||||
|
|
||||||
opacity: .01;
|
|
||||||
transform: translate3d(-9999px, 0, 0);
|
|
||||||
|
|
||||||
&.show-backdrop {
|
|
||||||
transform: translate3d(0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,14 +181,14 @@ import { GestureController } from '../../gestures/gesture-controller';
|
|||||||
'role': 'navigation'
|
'role': 'navigation'
|
||||||
},
|
},
|
||||||
template: `
|
template: `
|
||||||
<ng-content></ng-content>
|
<div class="menu-inner"><ng-content></ng-content></div>
|
||||||
<ion-backdrop (click)="bdClick($event)" disableScroll="false"></ion-backdrop>
|
<ion-backdrop (click)="bdClick($event)" disableScroll="false"></ion-backdrop>
|
||||||
`,
|
`,
|
||||||
directives: [Backdrop],
|
directives: [Backdrop],
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
})
|
})
|
||||||
export class Menu extends Ion {
|
export class Menu {
|
||||||
private _preventTime: number = 0;
|
private _preventTime: number = 0;
|
||||||
private _cntEle: HTMLElement;
|
private _cntEle: HTMLElement;
|
||||||
private _cntGesture: MenuContentGesture;
|
private _cntGesture: MenuContentGesture;
|
||||||
@ -303,9 +303,7 @@ export class Menu extends Ion {
|
|||||||
private _keyboard: Keyboard,
|
private _keyboard: Keyboard,
|
||||||
private _zone: NgZone,
|
private _zone: NgZone,
|
||||||
public gestureCtrl: GestureController
|
public gestureCtrl: GestureController
|
||||||
) {
|
) { }
|
||||||
super(_elementRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -576,11 +574,15 @@ export class Menu extends Ion {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNativeElement(): HTMLElement {
|
||||||
|
return this._elementRef.nativeElement;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
getMenuElement(): HTMLElement {
|
getMenuElement(): HTMLElement {
|
||||||
return this.getNativeElement();
|
return <HTMLElement>this.getNativeElement().querySelector('.menu-inner');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -597,6 +599,10 @@ export class Menu extends Ion {
|
|||||||
return this.backdrop.getNativeElement();
|
return this.backdrop.getNativeElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
width(): number {
|
||||||
|
return this.getMenuElement().offsetWidth;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
$menu-wp-background: #f2f2f2 !default;
|
$menu-wp-background: #f2f2f2 !default;
|
||||||
|
|
||||||
|
|
||||||
ion-menu {
|
.menu-inner {
|
||||||
background: $menu-wp-background;
|
background: $menu-wp-background;
|
||||||
}
|
}
|
||||||
|
@ -49,21 +49,22 @@ export class SlideGesture extends PanGesture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onDragMove(ev: any) {
|
onDragMove(ev: any) {
|
||||||
|
let slide = this.slide;
|
||||||
let coord = <any>pointerCoord(ev);
|
let coord = <any>pointerCoord(ev);
|
||||||
let newPos = coord[this.direction];
|
let newPos = coord[this.direction];
|
||||||
let newTimestamp = Date.now();
|
let newTimestamp = Date.now();
|
||||||
let velocity = (newPos - this.slide.pos) / (newTimestamp - this.slide.timestamp);
|
let velocity = (newPos - slide.pos) / (newTimestamp - slide.timestamp);
|
||||||
|
|
||||||
this.slide.pos = newPos;
|
slide.pos = newPos;
|
||||||
this.slide.timestamp = newTimestamp;
|
slide.timestamp = newTimestamp;
|
||||||
this.slide.distance = clamp(
|
slide.distance = clamp(
|
||||||
this.slide.min,
|
slide.min,
|
||||||
newPos - this.slide.pointerStartPos + this.slide.elementStartPos,
|
newPos - slide.pointerStartPos + slide.elementStartPos,
|
||||||
this.slide.max
|
slide.max
|
||||||
);
|
);
|
||||||
this.slide.velocity = velocity;
|
slide.velocity = velocity;
|
||||||
this.slide.delta = newPos - this.slide.pointerStartPos;
|
slide.delta = newPos - slide.pointerStartPos;
|
||||||
this.onSlide(this.slide, ev);
|
this.onSlide(slide, ev);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user