@@ -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. */
@@ -114,7 +112,7 @@ export class MatDrawerContent implements AfterContentInit {
114
112
host : {
115
113
'class' : 'mat-drawer' ,
116
114
'[@transform]' : '_animationState' ,
117
- '(@transform.start)' : '_onAnimationStart()' ,
115
+ '(@transform.start)' : '_onAnimationStart($event )' ,
118
116
'(@transform.done)' : '_onAnimationEnd($event)' ,
119
117
'(keydown)' : 'handleKeydown($event)' ,
120
118
// must prevent the browser from aligning text based on value
@@ -174,7 +172,7 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
174
172
private _opened : boolean = false ;
175
173
176
174
/** Emits whenever the drawer has started animating. */
177
- _animationStarted = new EventEmitter < void > ( ) ;
175
+ _animationStarted = new EventEmitter < AnimationEvent > ( ) ;
178
176
179
177
/** Whether the drawer is animating. Used to prevent overlapping animations. */
180
178
_isAnimating = false ;
@@ -317,9 +315,9 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
317
315
}
318
316
}
319
317
320
- _onAnimationStart ( ) {
318
+ _onAnimationStart ( event : AnimationEvent ) {
321
319
this . _isAnimating = true ;
322
- this . _animationStarted . emit ( ) ;
320
+ this . _animationStarted . emit ( event ) ;
323
321
}
324
322
325
323
_onAnimationEnd ( event : AnimationEvent ) {
@@ -448,13 +446,19 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
448
446
* is properly hidden.
449
447
*/
450
448
private _watchDrawerToggle ( drawer : MatDrawer ) : void {
451
- takeUntil . call ( drawer . _animationStarted , this . _drawers . changes ) . subscribe ( ( ) => {
452
- // Set the transition class on the container so that the animations occur. This should not
453
- // be set initially because animations should only be triggered via a change in state.
454
- this . _renderer . addClass ( this . _element . nativeElement , 'mat-drawer-transition' ) ;
455
- this . _updateContentMargins ( ) ;
456
- this . _changeDetectorRef . markForCheck ( ) ;
457
- } ) ;
449
+ RxChain . from ( drawer . _animationStarted )
450
+ . call ( takeUntil , this . _drawers . changes )
451
+ . call ( filter , ( event : AnimationEvent ) => event . fromState !== event . toState )
452
+ . subscribe ( ( event : AnimationEvent ) => {
453
+ // Set the transition class on the container so that the animations occur. This should not
454
+ // be set initially because animations should only be triggered via a change in state.
455
+ if ( event . toState !== 'open-instant' ) {
456
+ this . _renderer . addClass ( this . _element . nativeElement , 'mat-drawer-transition' ) ;
457
+ }
458
+
459
+ this . _updateContentMargins ( ) ;
460
+ this . _changeDetectorRef . markForCheck ( ) ;
461
+ } ) ;
458
462
459
463
if ( drawer . mode !== 'side' ) {
460
464
takeUntil . call ( merge ( drawer . onOpen , drawer . onClose ) , this . _drawers . changes ) . subscribe ( ( ) =>
@@ -463,8 +467,8 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
463
467
}
464
468
465
469
/**
466
- * Subscribes to drawer onPositionChanged event in order to re-validate drawers when the position
467
- * changes.
470
+ * Subscribes to drawer onPositionChanged event in order to
471
+ * re-validate drawers when the position changes.
468
472
*/
469
473
private _watchDrawerPosition ( drawer : MatDrawer ) : void {
470
474
if ( ! drawer ) {
0 commit comments