@@ -42,6 +42,11 @@ export class Platform {
42
42
private _bbActions : BackButtonAction [ ] = [ ] ;
43
43
private _registry : { [ name : string ] : PlatformConfig } ;
44
44
private _default : string ;
45
+ private _pW = 0 ;
46
+ private _pH = 0 ;
47
+ private _lW = 0 ;
48
+ private _lH = 0 ;
49
+ private _isPortrait : boolean = null ;
45
50
46
51
/** @private */
47
52
zone : NgZone ;
@@ -436,7 +441,8 @@ export class Platform {
436
441
* which reduces the chance of multiple and expensive DOM reads.
437
442
*/
438
443
width ( ) : number {
439
- return windowDimensions ( ) . width ;
444
+ this . _calcDim ( ) ;
445
+ return this . _isPortrait ? this . _pW : this . _lW ;
440
446
}
441
447
442
448
/**
@@ -445,14 +451,16 @@ export class Platform {
445
451
* which reduces the chance of multiple and expensive DOM reads.
446
452
*/
447
453
height ( ) : number {
448
- return windowDimensions ( ) . height ;
454
+ this . _calcDim ( ) ;
455
+ return this . _isPortrait ? this . _pH : this . _lH ;
449
456
}
450
457
451
458
/**
452
459
* Returns `true` if the app is in portait mode.
453
460
*/
454
461
isPortrait ( ) : boolean {
455
- return this . width ( ) < this . height ( ) ;
462
+ this . _calcDim ( ) ;
463
+ return this . _isPortrait ;
456
464
}
457
465
458
466
/**
@@ -462,19 +470,49 @@ export class Platform {
462
470
return ! this . isPortrait ( ) ;
463
471
}
464
472
473
+ /**
474
+ * @private
475
+ */
476
+ _calcDim ( ) {
477
+ if ( this . _isPortrait === null ) {
478
+ const winDimensions = windowDimensions ( ) ;
479
+ const screenWidth = window . screen . width || winDimensions . width ;
480
+ const screenHeight = window . screen . height || winDimensions . height ;
481
+
482
+ if ( screenWidth < screenHeight ) {
483
+ this . _isPortrait = true ;
484
+ if ( this . _pW < winDimensions . width ) {
485
+ this . _pW = winDimensions . width ;
486
+ }
487
+ if ( this . _pH < winDimensions . height ) {
488
+ this . _pH = winDimensions . height ;
489
+ }
490
+
491
+ } else {
492
+ this . _isPortrait = false ;
493
+ if ( this . _lW < winDimensions . width ) {
494
+ this . _lW = winDimensions . width ;
495
+ }
496
+ if ( this . _lH < winDimensions . height ) {
497
+ this . _lH = winDimensions . height ;
498
+ }
499
+ }
500
+ }
501
+ }
502
+
465
503
/**
466
504
* @private
467
505
*/
468
506
windowResize ( ) {
469
- const self = this ;
470
- clearTimeout ( self . _resizeTm ) ;
507
+ clearTimeout ( this . _resizeTm ) ;
471
508
472
- self . _resizeTm = setTimeout ( ( ) => {
509
+ this . _resizeTm = setTimeout ( ( ) => {
473
510
flushDimensionCache ( ) ;
511
+ this . _isPortrait = null ;
474
512
475
- for ( let i = 0 ; i < self . _onResizes . length ; i ++ ) {
513
+ for ( let i = 0 ; i < this . _onResizes . length ; i ++ ) {
476
514
try {
477
- self . _onResizes [ i ] ( ) ;
515
+ this . _onResizes [ i ] ( ) ;
478
516
} catch ( e ) {
479
517
console . error ( e ) ;
480
518
}
0 commit comments