@@ -33,10 +33,8 @@ import {
33
33
} from '@angular/core' ;
34
34
import { DOCUMENT } from '@angular/platform-browser' ;
35
35
import { merge } from 'rxjs/observable/merge' ;
36
- import { first } from 'rxjs/operator/first' ;
37
- import { startWith } from 'rxjs/operator/startWith' ;
38
- import { takeUntil } from 'rxjs/operator/takeUntil' ;
39
36
import { Subject } from 'rxjs/Subject' ;
37
+ import { RxChain , filter , first , startWith , takeUntil } from '@angular/cdk/rxjs' ;
40
38
41
39
42
40
/** Throws an exception when two MatDrawer are matching the same position. */
@@ -117,7 +115,7 @@ export class MatDrawerContent implements AfterContentInit {
117
115
host : {
118
116
'class' : 'mat-drawer' ,
119
117
'[@transform]' : '_animationState' ,
120
- '(@transform.start)' : '_onAnimationStart()' ,
118
+ '(@transform.start)' : '_onAnimationStart($event )' ,
121
119
'(@transform.done)' : '_onAnimationEnd($event)' ,
122
120
'(keydown)' : 'handleKeydown($event)' ,
123
121
// must prevent the browser from aligning text based on value
@@ -177,7 +175,7 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
177
175
private _opened : boolean = false ;
178
176
179
177
/** Emits whenever the drawer has started animating. */
180
- _animationStarted = new EventEmitter < void > ( ) ;
178
+ _animationStarted = new EventEmitter < AnimationEvent > ( ) ;
181
179
182
180
/** Whether the drawer is animating. Used to prevent overlapping animations. */
183
181
_isAnimating = false ;
@@ -320,9 +318,9 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
320
318
}
321
319
}
322
320
323
- _onAnimationStart ( ) {
321
+ _onAnimationStart ( event : AnimationEvent ) {
324
322
this . _isAnimating = true ;
325
- this . _animationStarted . emit ( ) ;
323
+ this . _animationStarted . emit ( event ) ;
326
324
}
327
325
328
326
_onAnimationEnd ( event : AnimationEvent ) {
@@ -453,13 +451,19 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
453
451
* is properly hidden.
454
452
*/
455
453
private _watchDrawerToggle ( drawer : MatDrawer ) : void {
456
- takeUntil . call ( drawer . _animationStarted , this . _drawers . changes ) . subscribe ( ( ) => {
457
- // Set the transition class on the container so that the animations occur. This should not
458
- // be set initially because animations should only be triggered via a change in state.
459
- this . _renderer . addClass ( this . _element . nativeElement , 'mat-drawer-transition' ) ;
460
- this . _updateContentMargins ( ) ;
461
- this . _changeDetectorRef . markForCheck ( ) ;
462
- } ) ;
454
+ RxChain . from ( drawer . _animationStarted )
455
+ . call ( takeUntil , this . _drawers . changes )
456
+ . call ( filter , ( event : AnimationEvent ) => event . fromState !== event . toState )
457
+ . subscribe ( ( event : AnimationEvent ) => {
458
+ // Set the transition class on the container so that the animations occur. This should not
459
+ // be set initially because animations should only be triggered via a change in state.
460
+ if ( event . toState !== 'open-instant' ) {
461
+ this . _renderer . addClass ( this . _element . nativeElement , 'mat-drawer-transition' ) ;
462
+ }
463
+
464
+ this . _updateContentMargins ( ) ;
465
+ this . _changeDetectorRef . markForCheck ( ) ;
466
+ } ) ;
463
467
464
468
if ( drawer . mode !== 'side' ) {
465
469
takeUntil . call ( merge ( drawer . onOpen , drawer . onClose ) , this . _drawers . changes ) . subscribe ( ( ) =>
@@ -468,8 +472,8 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
468
472
}
469
473
470
474
/**
471
- * Subscribes to drawer onPositionChanged event in order to re-validate drawers when the position
472
- * changes.
475
+ * Subscribes to drawer onPositionChanged event in order to
476
+ * re-validate drawers when the position changes.
473
477
*/
474
478
private _watchDrawerPosition ( drawer : MatDrawer ) : void {
475
479
if ( ! drawer ) {
0 commit comments