@@ -14,14 +14,15 @@ import {
1414 Output ,
1515 Renderer ,
1616 SimpleChange ,
17- TemplateRef ,
18- ViewChild
17+ ViewChild ,
18+ PLATFORM_ID
1919} from '@angular/core' ;
2020import { fromEvent , interval , Subscription } from 'rxjs' ;
2121import { debounce } from 'rxjs/operators' ;
2222import { IgxNavigationService , IToggleView } from '../core/navigation' ;
2323import { HammerGesturesManager } from '../core/touch' ;
2424import { IgxNavDrawerMiniTemplateDirective , IgxNavDrawerTemplateDirective } from './navigation-drawer.directives' ;
25+ import { isPlatformBrowser } from '@angular/common' ;
2526
2627let NEXT_ID = 0 ;
2728/**
@@ -595,18 +596,26 @@ export class IgxNavigationDrawerComponent implements
595596 }
596597
597598 private getWindowWidth ( ) {
599+ if ( ! isPlatformBrowser ( PLATFORM_ID ) ) {
600+ return ;
601+ }
602+
598603 return ( window . innerWidth > 0 ) ? window . innerWidth : screen . width ;
599604 }
600605
601606 /**
602607 * Sets the drawer width.
603608 */
604609 private setDrawerWidth ( width : string ) {
605- requestAnimationFrame ( ( ) => {
606- if ( this . drawer ) {
607- this . renderer . setElementStyle ( this . drawer , 'width' , width ) ;
608- }
609- } ) ;
610+ if ( isPlatformBrowser ( PLATFORM_ID ) ) {
611+ requestAnimationFrame ( ( ) => {
612+ if ( this . drawer ) {
613+ this . renderer . setElementStyle ( this . drawer , 'width' , width ) ;
614+ }
615+ } ) ;
616+ } else {
617+ this . renderer . setElementStyle ( this . drawer , 'width' , width ) ;
618+ }
610619 }
611620
612621 /**
@@ -632,7 +641,7 @@ export class IgxNavigationDrawerComponent implements
632641 this . _touchManager . addGlobalEventListener ( 'document' , 'panmove' , this . pan ) ;
633642 this . _touchManager . addGlobalEventListener ( 'document' , 'panend' , this . panEnd ) ;
634643 }
635- if ( ! this . _resizeObserver ) {
644+ if ( ! this . _resizeObserver && isPlatformBrowser ( PLATFORM_ID ) ) {
636645 this . _resizeObserver = fromEvent ( window , 'resize' ) . pipe ( debounce ( ( ) => interval ( 150 ) ) )
637646 . subscribe ( ( value ) => {
638647 this . checkPinThreshold ( value ) ;
@@ -788,19 +797,27 @@ export class IgxNavigationDrawerComponent implements
788797 * @param opacity optional value to apply to the overlay
789798 */
790799 private setXSize ( x : number , opacity ?: string ) {
791- // Angular polyfills patches window.requestAnimationFrame, but switch to DomAdapter API (TODO)
792- window . requestAnimationFrame ( ( ) => {
793- if ( this . hasAnimateWidth ) {
794- this . renderer . setElementStyle ( this . drawer , 'width' , x ? Math . abs ( x ) + 'px' : '' ) ;
795- } else {
796- this . renderer . setElementStyle ( this . drawer , 'transform' , x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
797- this . renderer . setElementStyle ( this . drawer , '-webkit-transform' ,
798- x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
799- }
800- if ( opacity !== undefined ) {
801- this . renderer . setElementStyle ( this . overlay , 'opacity' , opacity ) ;
802- }
803- } ) ;
800+ if ( isPlatformBrowser ( PLATFORM_ID ) ) {
801+ // Angular polyfills patches window.requestAnimationFrame, but switch to DomAdapter API (TODO)
802+ window . requestAnimationFrame ( ( ) => {
803+ this . setXSizeInternal ( x , opacity ) ;
804+ } ) ;
805+ } else {
806+ this . setXSizeInternal ( x , opacity ) ;
807+ }
808+ }
809+
810+ private setXSizeInternal ( x : number , opacity ?: string ) {
811+ if ( this . hasAnimateWidth ) {
812+ this . renderer . setElementStyle ( this . drawer , 'width' , x ? Math . abs ( x ) + 'px' : '' ) ;
813+ } else {
814+ this . renderer . setElementStyle ( this . drawer , 'transform' , x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
815+ this . renderer . setElementStyle ( this . drawer , '-webkit-transform' ,
816+ x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
817+ }
818+ if ( opacity !== undefined ) {
819+ this . renderer . setElementStyle ( this . overlay , 'opacity' , opacity ) ;
820+ }
804821 }
805822
806823 private toggleOpenedEvent = ( evt ?) => {
0 commit comments