diff --git a/src/platform/platform.ts b/src/platform/platform.ts index 417311ea77..dac7d1aae3 100644 --- a/src/platform/platform.ts +++ b/src/platform/platform.ts @@ -42,6 +42,11 @@ export class Platform { private _bbActions: BackButtonAction[] = []; private _registry: {[name: string]: PlatformConfig}; private _default: string; + private _pW = 0; + private _pH = 0; + private _lW = 0; + private _lH = 0; + private _isPortrait: boolean = null; /** @private */ zone: NgZone; @@ -436,7 +441,8 @@ export class Platform { * which reduces the chance of multiple and expensive DOM reads. */ width(): number { - return windowDimensions().width; + this._calcDim(); + return this._isPortrait ? this._pW : this._lW; } /** @@ -445,14 +451,16 @@ export class Platform { * which reduces the chance of multiple and expensive DOM reads. */ height(): number { - return windowDimensions().height; + this._calcDim(); + return this._isPortrait ? this._pH : this._lH; } /** * Returns `true` if the app is in portait mode. */ isPortrait(): boolean { - return this.width() < this.height(); + this._calcDim(); + return this._isPortrait; } /** @@ -462,19 +470,49 @@ export class Platform { return !this.isPortrait(); } + /** + * @private + */ + _calcDim() { + if (this._isPortrait === null) { + const winDimensions = windowDimensions(); + const screenWidth = window.screen.width || winDimensions.width; + const screenHeight = window.screen.height || winDimensions.height; + + if (screenWidth < screenHeight) { + this._isPortrait = true; + if (this._pW < winDimensions.width) { + this._pW = winDimensions.width; + } + if (this._pH < winDimensions.height) { + this._pH = winDimensions.height; + } + + } else { + this._isPortrait = false; + if (this._lW < winDimensions.width) { + this._lW = winDimensions.width; + } + if (this._lH < winDimensions.height) { + this._lH = winDimensions.height; + } + } + } + } + /** * @private */ windowResize() { - const self = this; - clearTimeout(self._resizeTm); + clearTimeout(this._resizeTm); - self._resizeTm = setTimeout(() => { + this._resizeTm = setTimeout(() => { flushDimensionCache(); + this._isPortrait = null; - for (let i = 0; i < self._onResizes.length; i++) { + for (let i = 0; i < this._onResizes.length; i++) { try { - self._onResizes[i](); + this._onResizes[i](); } catch (e) { console.error(e); }