@@ -38,8 +38,6 @@ import {Subject} from 'rxjs/Subject';
3838import { MatSnackBarConfig } from './snack-bar-config' ;
3939
4040
41- export type SnackBarState = 'visible' | 'hidden' | 'void' ;
42-
4341// TODO(jelbourn): we can't use constants from animation.ts here because you can't use
4442// a text interpolation in anything that is analyzed statically with ngc (for AoT compile).
4543export const SHOW_ANIMATION = '225ms cubic-bezier(0.4,0.0,1,1)' ;
@@ -60,7 +58,7 @@ export const HIDE_ANIMATION = '195ms cubic-bezier(0.0,0.0,0.2,1)';
6058 host : {
6159 'role' : 'alert' ,
6260 'class' : 'mat-snack-bar-container' ,
63- '[@state]' : 'getAnimationState() ' ,
61+ '[@state]' : '_animationState ' ,
6462 '(@state.done)' : 'onAnimationEnd($event)'
6563 } ,
6664 animations : [
@@ -93,7 +91,7 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
9391 _onEnter : Subject < any > = new Subject ( ) ;
9492
9593 /** The state of the snack bar animations. */
96- private _animationState : SnackBarState ;
94+ _animationState = 'void' ;
9795
9896 /** The snack bar configuration. */
9997 snackBarConfig : MatSnackBarConfig ;
@@ -106,14 +104,6 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
106104 super ( ) ;
107105 }
108106
109- /**
110- * Gets the current animation state both combining one of the possibilities from
111- * SnackBarState and the vertical location.
112- */
113- getAnimationState ( ) : string {
114- return `${ this . _animationState } -${ this . snackBarConfig . verticalPosition } ` ;
115- }
116-
117107 /** Attach a component portal as content to this snack bar container. */
118108 attachComponentPortal < T > ( portal : ComponentPortal < T > ) : ComponentRef < T > {
119109 if ( this . _portalHost . hasAttached ( ) ) {
@@ -146,11 +136,13 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
146136
147137 /** Handle end of animations, updating the state of the snackbar. */
148138 onAnimationEnd ( event : AnimationEvent ) {
149- if ( event . toState === 'void' || event . toState . startsWith ( 'hidden' ) ) {
139+ const { fromState, toState} = event ;
140+
141+ if ( ( toState === 'void' && fromState !== 'void' ) || toState . startsWith ( 'hidden' ) ) {
150142 this . _completeExit ( ) ;
151143 }
152144
153- if ( event . toState . startsWith ( 'visible' ) ) {
145+ if ( toState . startsWith ( 'visible' ) ) {
154146 // Note: we shouldn't use `this` inside the zone callback,
155147 // because it can cause a memory leak.
156148 const onEnter = this . _onEnter ;
@@ -165,14 +157,14 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
165157 /** Begin animation of snack bar entrance into view. */
166158 enter ( ) : void {
167159 if ( ! this . _destroyed ) {
168- this . _animationState = ' visible' ;
160+ this . _animationState = ` visible- ${ this . snackBarConfig . verticalPosition } ` ;
169161 this . _changeDetectorRef . detectChanges ( ) ;
170162 }
171163 }
172164
173165 /** Begin animation of the snack bar exiting from view. */
174166 exit ( ) : Observable < void > {
175- this . _animationState = ' hidden' ;
167+ this . _animationState = ` hidden- ${ this . snackBarConfig . verticalPosition } ` ;
176168 return this . _onExit ;
177169 }
178170
0 commit comments