mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
cache window dimensions
This commit is contained in:
@ -11,7 +11,7 @@ export * from 'ionic/components/icon/icon'
|
|||||||
export * from 'ionic/components/item/item'
|
export * from 'ionic/components/item/item'
|
||||||
export * from 'ionic/components/item/item-group'
|
export * from 'ionic/components/item/item-group'
|
||||||
export * from 'ionic/components/menu/menu'
|
export * from 'ionic/components/menu/menu'
|
||||||
export * from 'ionic/components/menu/extensions/types'
|
export * from 'ionic/components/menu/menu-types'
|
||||||
export * from 'ionic/components/menu/menu-toggle'
|
export * from 'ionic/components/menu/menu-toggle'
|
||||||
export * from 'ionic/components/text-input/text-input'
|
export * from 'ionic/components/text-input/text-input'
|
||||||
export * from 'ionic/components/text-input/label'
|
export * from 'ionic/components/text-input/label'
|
||||||
|
@ -263,7 +263,7 @@ export function ionicBootstrap(rootComponentType, config) {
|
|||||||
config = new IonicConfig(config);
|
config = new IonicConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
let platform = new IonicPlatform(window);
|
let platform = new IonicPlatform();
|
||||||
|
|
||||||
// create the base IonicApp
|
// create the base IonicApp
|
||||||
let app = initApp(window, document, config, platform);
|
let app = initApp(window, document, config, platform);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Menu} from '../menu';
|
import {Menu} from './menu';
|
||||||
import {SlideEdgeGesture} from 'ionic/gestures/slide-edge-gesture';
|
import {SlideEdgeGesture} from 'ionic/gestures/slide-edge-gesture';
|
||||||
|
|
||||||
|
|
@ -4,12 +4,8 @@
|
|||||||
// 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] {
|
ion-menu[type=reveal].show-menu {
|
||||||
transform: translate3d(-9999px, 0px, 0px);
|
|
||||||
|
|
||||||
&.show-menu {
|
|
||||||
transform: translate3d(0px, 0px, 0px);
|
transform: translate3d(0px, 0px, 0px);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-content-reveal {
|
.menu-content-reveal {
|
||||||
@ -26,7 +22,6 @@ ion-menu[type=reveal] {
|
|||||||
ion-menu[type=overlay] {
|
ion-menu[type=overlay] {
|
||||||
z-index: $z-index-menu-overlay;
|
z-index: $z-index-menu-overlay;
|
||||||
box-shadow: $menu-shadow;
|
box-shadow: $menu-shadow;
|
||||||
transform: translate3d(-9999px, 0px, 0px);
|
|
||||||
|
|
||||||
backdrop {
|
backdrop {
|
||||||
display: block;
|
display: block;
|
@ -1,4 +1,4 @@
|
|||||||
import {Menu} from '../menu';
|
import {Menu} from './menu';
|
||||||
import {Animation} from 'ionic/animations/animation';
|
import {Animation} from 'ionic/animations/animation';
|
||||||
|
|
||||||
|
|
@ -22,6 +22,8 @@ ion-menu {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
background: $menu-background;
|
background: $menu-background;
|
||||||
|
|
||||||
|
transform: translate3d(-9999px, 0px, 0px);
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-menu[side=right] {
|
ion-menu[side=right] {
|
||||||
|
@ -4,7 +4,7 @@ import {Ion} from '../ion';
|
|||||||
import {IonicApp} from '../app/app';
|
import {IonicApp} from '../app/app';
|
||||||
import {IonicConfig} from '../../config/config';
|
import {IonicConfig} from '../../config/config';
|
||||||
import {IonicComponent} from '../../config/annotations';
|
import {IonicComponent} from '../../config/annotations';
|
||||||
import * as gestures from './extensions/gestures';
|
import * as gestures from './menu-gestures';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
import {Gesture} from 'ionic/gestures/gesture';
|
import {Gesture} from 'ionic/gestures/gesture';
|
||||||
import * as util from 'ionic/util';
|
import * as util from 'ionic/util';
|
||||||
//import Hammer from 'hammer';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* BUG(ajoslin): HammerJS 2.x does not have an alternative to HammerJS 1.x's
|
|
||||||
* dragLockToAxis, so a vertical and horizontal gesture can happen at the same time.
|
|
||||||
*/
|
|
||||||
export class DragGesture extends Gesture {
|
export class DragGesture extends Gesture {
|
||||||
constructor(element, opts = {}) {
|
constructor(element, opts = {}) {
|
||||||
util.defaults(opts, {});
|
util.defaults(opts, {});
|
||||||
super(element, opts);
|
super(element, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
listen() {
|
listen() {
|
||||||
super.listen();
|
super.listen();
|
||||||
this.on('panstart', ev => {
|
this.on('panstart', ev => {
|
||||||
@ -33,6 +30,7 @@ export class DragGesture extends Gesture {
|
|||||||
// ev.stopPropagation()
|
// ev.stopPropagation()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onDrag() {}
|
onDrag() {}
|
||||||
onDragStart() {}
|
onDragStart() {}
|
||||||
onDragEnd() {}
|
onDragEnd() {}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import {SlideGesture} from 'ionic/gestures/slide-gesture';
|
import {SlideGesture} from 'ionic/gestures/slide-gesture';
|
||||||
import * as util from 'ionic/util';
|
import {defaults} from '../util/util';
|
||||||
|
import {windowDimensions} from '../util/dom';
|
||||||
|
|
||||||
|
|
||||||
export class SlideEdgeGesture extends SlideGesture {
|
export class SlideEdgeGesture extends SlideGesture {
|
||||||
constructor(element: Element, opts: Object = {}) {
|
constructor(element: Element, opts: Object = {}) {
|
||||||
util.defaults(opts, {
|
defaults(opts, {
|
||||||
edge: 'left',
|
edge: 'left',
|
||||||
threshold: 50
|
threshold: 50
|
||||||
});
|
});
|
||||||
@ -22,8 +24,8 @@ export class SlideEdgeGesture extends SlideGesture {
|
|||||||
return {
|
return {
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: window.innerWidth,
|
width: windowDimensions().width,
|
||||||
height: window.innerHeight
|
height: windowDimensions().height
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
"components/list/list",
|
"components/list/list",
|
||||||
"components/card/card",
|
"components/card/card",
|
||||||
"components/menu/menu",
|
"components/menu/menu",
|
||||||
"components/menu/extensions/types",
|
"components/menu/menu-types",
|
||||||
"components/modal/modal",
|
"components/modal/modal",
|
||||||
"components/nav-bar/nav-bar",
|
"components/nav-bar/nav-bar",
|
||||||
"components/popup/popup",
|
"components/popup/popup",
|
||||||
|
@ -7,8 +7,7 @@ import * as dom from '../util/dom';
|
|||||||
*/
|
*/
|
||||||
export class IonicPlatform {
|
export class IonicPlatform {
|
||||||
|
|
||||||
constructor(window) {
|
constructor() {
|
||||||
this._window = window;
|
|
||||||
this._settings = {};
|
this._settings = {};
|
||||||
this._platforms = [];
|
this._platforms = [];
|
||||||
this._versions = {};
|
this._versions = {};
|
||||||
@ -131,19 +130,11 @@ export class IonicPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
width() {
|
width() {
|
||||||
if (!this._w) {
|
return dom.windowDimensions().width;
|
||||||
this._w = this._window.innerWidth;
|
|
||||||
this._h = this._window.innerHeight;
|
|
||||||
}
|
|
||||||
return this._w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
height() {
|
height() {
|
||||||
if (!this._h) {
|
return dom.windowDimensions().height;
|
||||||
this._w = this._window.innerWidth;
|
|
||||||
this._h = this._window.innerHeight;
|
|
||||||
}
|
|
||||||
return this._h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isPortrait() {
|
isPortrait() {
|
||||||
@ -159,7 +150,6 @@ export class IonicPlatform {
|
|||||||
clearTimeout(self._resizeTimer);
|
clearTimeout(self._resizeTimer);
|
||||||
|
|
||||||
self._resizeTimer = setTimeout(() => {
|
self._resizeTimer = setTimeout(() => {
|
||||||
this._w = this._h = 0;
|
|
||||||
dom.flushDimensionCache();
|
dom.flushDimensionCache();
|
||||||
|
|
||||||
for (let i = 0; i < self._onResizes.length; i++) {
|
for (let i = 0; i < self._onResizes.length; i++) {
|
||||||
|
@ -228,7 +228,7 @@ export function closest(el, selector) {
|
|||||||
export function getDimensions(ele) {
|
export function getDimensions(ele) {
|
||||||
if (!ele.ionicId) {
|
if (!ele.ionicId) {
|
||||||
ele.ionicId = ++ionicElementIds;
|
ele.ionicId = ++ionicElementIds;
|
||||||
if (ele.ionicId % 200) {
|
if (ele.ionicId % 100 === 0) {
|
||||||
// periodically flush dimensions
|
// periodically flush dimensions
|
||||||
flushDimensionCache();
|
flushDimensionCache();
|
||||||
}
|
}
|
||||||
@ -245,6 +245,16 @@ export function getDimensions(ele) {
|
|||||||
return dimensions;
|
return dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function windowDimensions() {
|
||||||
|
if (!elementDimensions.win) {
|
||||||
|
elementDimensions.win = {
|
||||||
|
width: window.innerWidth,
|
||||||
|
height: window.innerHeight
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return elementDimensions.win;
|
||||||
|
}
|
||||||
|
|
||||||
export function flushDimensionCache() {
|
export function flushDimensionCache() {
|
||||||
elementDimensions = {};
|
elementDimensions = {};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user