@@ -67,28 +67,20 @@ export function MAT_DRAWER_DEFAULT_AUTOSIZE_FACTORY(): boolean {
67
67
template : '<ng-content></ng-content>' ,
68
68
host : {
69
69
'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' ,
72
72
} ,
73
73
changeDetection : ChangeDetectionStrategy . OnPush ,
74
74
encapsulation : ViewEncapsulation . None ,
75
75
} )
76
76
export 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
-
84
77
constructor (
85
78
private _changeDetectorRef : ChangeDetectorRef ,
86
- @Inject ( forwardRef ( ( ) => MatDrawerContainer ) ) private _container : MatDrawerContainer ) {
79
+ @Inject ( forwardRef ( ( ) => MatDrawerContainer ) ) public _container : MatDrawerContainer ) {
87
80
}
88
81
89
82
ngAfterContentInit ( ) {
90
- this . _container . _contentMargins . subscribe ( margins => {
91
- this . _margins = margins ;
83
+ this . _container . _contentMarginChanges . subscribe ( ( ) => {
92
84
this . _changeDetectorRef . markForCheck ( ) ;
93
85
} ) ;
94
86
}
@@ -466,7 +458,14 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
466
458
/** Emits on every ngDoCheck. Used for debouncing reflows. */
467
459
private readonly _doCheckSubject = new Subject < void > ( ) ;
468
460
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 } > ( ) ;
470
469
471
470
/** Reference to the CdkScrollable instance that wraps the scrollable content. */
472
471
@ViewChild ( CdkScrollable ) scrollable : CdkScrollable ;
@@ -699,7 +698,13 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
699
698
}
700
699
}
701
700
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
+
704
709
}
705
710
}
0 commit comments