@@ -67,28 +67,20 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
6767 template : '<ng-content></ng-content>' ,
6868 host : {
6969 'class' : 'mat-drawer-content' ,
70- '[style.margin-left.px]' : '_margins .left' ,
71- '[style.margin-right.px]' : '_margins .right' ,
70+ '[style.margin-left.px]' : '_container._contentMargins .left' ,
71+ '[style.margin-right.px]' : '_container._contentMargins .right' ,
7272 } ,
7373 changeDetection : ChangeDetectionStrategy . OnPush ,
7474 encapsulation : ViewEncapsulation . None ,
7575} )
7676export class MatDrawerContent implements AfterContentInit {
77- /**
78- * Margins to be applied to the content. These are used to push / shrink the drawer content when a
79- * drawer is open. We use margin rather than transform even for push mode because transform breaks
80- * fixed position elements inside of the transformed element.
81- */
82- _margins : { left : number | null , right : number | null } = { left : null , right : null } ;
83-
8477 constructor (
8578 private _changeDetectorRef : ChangeDetectorRef ,
86- @Inject ( forwardRef ( ( ) => MatDrawerContainer ) ) private _container : MatDrawerContainer ) {
79+ @Inject ( forwardRef ( ( ) => MatDrawerContainer ) ) public _container : MatDrawerContainer ) {
8780 }
8881
8982 ngAfterContentInit ( ) {
90- this . _container . _contentMargins . subscribe ( margins => {
91- this . _margins = margins ;
83+ this . _container . _contentMarginChanges . subscribe ( ( ) => {
9284 this . _changeDetectorRef . markForCheck ( ) ;
9385 } ) ;
9486 }
@@ -466,7 +458,14 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
466458 /** Emits on every ngDoCheck. Used for debouncing reflows. */
467459 private readonly _doCheckSubject = new Subject < void > ( ) ;
468460
469- readonly _contentMargins = new Subject < { left : number | null , right : number | null } > ( ) ;
461+ /**
462+ * Margins to be applied to the content. These are used to push / shrink the drawer content when a
463+ * drawer is open. We use margin rather than transform even for push mode because transform breaks
464+ * fixed position elements inside of the transformed element.
465+ */
466+ _contentMargins : { left : number | null , right : number | null } = { left : null , right : null } ;
467+
468+ readonly _contentMarginChanges = new Subject < { left : number | null , right : number | null } > ( ) ;
470469
471470 /** Reference to the CdkScrollable instance that wraps the scrollable content. */
472471 @ViewChild ( CdkScrollable ) scrollable : CdkScrollable ;
@@ -699,7 +698,13 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
699698 }
700699 }
701700
702- // Pull back into the NgZone since in some cases we could be outside.
703- this . _ngZone . run ( ( ) => this . _contentMargins . next ( { left, right} ) ) ;
701+ if ( left !== this . _contentMargins . left || right !== this . _contentMargins . right ) {
702+ this . _contentMargins = { left, right} ;
703+
704+ // Pull back into the NgZone since in some cases we could be outside. We need to be careful
705+ // to do it only when something changed, otherwise we can end up hitting the zone too often.
706+ this . _ngZone . run ( ( ) => this . _contentMarginChanges . next ( this . _contentMargins ) ) ;
707+ }
708+
704709 }
705710}
0 commit comments