@@ -38,8 +38,6 @@ import {Subject} from 'rxjs/Subject';
38
38
import { MatSnackBarConfig } from './snack-bar-config' ;
39
39
40
40
41
- export type SnackBarState = 'visible' | 'hidden' | 'void' ;
42
-
43
41
// TODO(jelbourn): we can't use constants from animation.ts here because you can't use
44
42
// a text interpolation in anything that is analyzed statically with ngc (for AoT compile).
45
43
export 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)';
60
58
host : {
61
59
'role' : 'alert' ,
62
60
'class' : 'mat-snack-bar-container' ,
63
- '[@state]' : 'getAnimationState() ' ,
61
+ '[@state]' : '_animationState ' ,
64
62
'(@state.done)' : 'onAnimationEnd($event)'
65
63
} ,
66
64
animations : [
@@ -93,7 +91,7 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
93
91
_onEnter : Subject < any > = new Subject ( ) ;
94
92
95
93
/** The state of the snack bar animations. */
96
- private _animationState : SnackBarState ;
94
+ _animationState = 'void' ;
97
95
98
96
/** The snack bar configuration. */
99
97
snackBarConfig : MatSnackBarConfig ;
@@ -106,14 +104,6 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
106
104
super ( ) ;
107
105
}
108
106
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
-
117
107
/** Attach a component portal as content to this snack bar container. */
118
108
attachComponentPortal < T > ( portal : ComponentPortal < T > ) : ComponentRef < T > {
119
109
if ( this . _portalHost . hasAttached ( ) ) {
@@ -146,11 +136,13 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
146
136
147
137
/** Handle end of animations, updating the state of the snackbar. */
148
138
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' ) ) {
150
142
this . _completeExit ( ) ;
151
143
}
152
144
153
- if ( event . toState . startsWith ( 'visible' ) ) {
145
+ if ( toState . startsWith ( 'visible' ) ) {
154
146
// Note: we shouldn't use `this` inside the zone callback,
155
147
// because it can cause a memory leak.
156
148
const onEnter = this . _onEnter ;
@@ -165,14 +157,14 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
165
157
/** Begin animation of snack bar entrance into view. */
166
158
enter ( ) : void {
167
159
if ( ! this . _destroyed ) {
168
- this . _animationState = ' visible' ;
160
+ this . _animationState = ` visible- ${ this . snackBarConfig . verticalPosition } ` ;
169
161
this . _changeDetectorRef . detectChanges ( ) ;
170
162
}
171
163
}
172
164
173
165
/** Begin animation of the snack bar exiting from view. */
174
166
exit ( ) : Observable < void > {
175
- this . _animationState = ' hidden' ;
167
+ this . _animationState = ` hidden- ${ this . snackBarConfig . verticalPosition } ` ;
176
168
return this . _onExit ;
177
169
}
178
170
0 commit comments