@@ -27,7 +27,7 @@ import {Subject} from 'rxjs/Subject';
27
27
28
28
29
29
30
- export type SnackBarState = 'initial' | ' visible' | 'complete ' | 'void' ;
30
+ export type SnackBarState = 'visible' | 'hidden ' | 'void' ;
31
31
32
32
// TODO(jelbourn): we can't use constants from animation.ts here because you can't use
33
33
// a text interpolation in anything that is analyzed statically with ngc (for AoT compile).
@@ -45,16 +45,22 @@ export const HIDE_ANIMATION = '195ms cubic-bezier(0.0,0.0,0.2,1)';
45
45
styleUrls : [ 'snack-bar-container.css' ] ,
46
46
host : {
47
47
'role' : 'alert' ,
48
- '[@state]' : 'animationState ' ,
48
+ '[@state]' : 'getAnimationState() ' ,
49
49
'(@state.done)' : 'onAnimationEnd($event)'
50
50
} ,
51
51
animations : [
52
52
trigger ( 'state' , [
53
- state ( 'initial' , style ( { transform : 'translateY(100%)' } ) ) ,
54
- state ( 'visible' , style ( { transform : 'translateY(0%)' } ) ) ,
55
- state ( 'complete' , style ( { transform : 'translateY(100%)' } ) ) ,
56
- transition ( 'visible => complete' , animate ( HIDE_ANIMATION ) ) ,
57
- transition ( 'initial => visible, void => visible' , animate ( SHOW_ANIMATION ) ) ,
53
+ // Animation from top.
54
+ state ( 'visible-top' , style ( { transform : 'translateY(0%)' } ) ) ,
55
+ state ( 'hidden-top' , style ( { transform : 'translateY(-100%)' } ) ) ,
56
+ transition ( 'visible-top => hidden-top' , animate ( HIDE_ANIMATION ) ) ,
57
+ transition ( 'void => visible-top' , animate ( SHOW_ANIMATION ) ) ,
58
+ // Animation from bottom.
59
+ state ( 'visible-bottom' , style ( { transform : 'translateY(0%)' } ) ) ,
60
+ state ( 'hidden-bottom' , style ( { transform : 'translateY(100%)' } ) ) ,
61
+ transition ( 'visible-bottom => hidden-bottom' , animate ( HIDE_ANIMATION ) ) ,
62
+ transition ( 'void => visible-bottom' ,
63
+ animate ( SHOW_ANIMATION ) ) ,
58
64
] )
59
65
] ,
60
66
} )
@@ -69,7 +75,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
69
75
private onEnter : Subject < any > = new Subject ( ) ;
70
76
71
77
/** The state of the snack bar animations. */
72
- animationState : SnackBarState = 'initial' ;
78
+ private animationState : SnackBarState ;
73
79
74
80
/** The snack bar configuration. */
75
81
snackBarConfig : MdSnackBarConfig ;
@@ -81,6 +87,14 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
81
87
super ( ) ;
82
88
}
83
89
90
+ /**
91
+ * Gets the current animation state both combining one of the possibilities from
92
+ * SnackBarState and the vertical location.
93
+ */
94
+ getAnimationState ( ) : string {
95
+ return `${ this . animationState } -${ this . snackBarConfig . verticalPosition } ` ;
96
+ }
97
+
84
98
/** Attach a component portal as content to this snack bar container. */
85
99
attachComponentPortal < T > ( portal : ComponentPortal < T > ) : ComponentRef < T > {
86
100
if ( this . _portalHost . hasAttached ( ) ) {
@@ -95,6 +109,14 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
95
109
}
96
110
}
97
111
112
+ if ( this . snackBarConfig . horizontalPosition === 'center' ) {
113
+ this . _renderer . addClass ( this . _elementRef . nativeElement , 'mat-snack-bar-center' ) ;
114
+ }
115
+
116
+ if ( this . snackBarConfig . verticalPosition === 'top' ) {
117
+ this . _renderer . addClass ( this . _elementRef . nativeElement , 'mat-snack-bar-top' ) ;
118
+ }
119
+
98
120
return this . _portalHost . attachComponentPortal ( portal ) ;
99
121
}
100
122
@@ -105,15 +127,14 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
105
127
106
128
/** Handle end of animations, updating the state of the snackbar. */
107
129
onAnimationEnd ( event : AnimationEvent ) {
108
- if ( event . toState === 'void' || event . toState === 'complete' ) {
130
+ if ( event . toState === 'void' || event . toState . startsWith ( 'hidden' ) ) {
109
131
this . _completeExit ( ) ;
110
132
}
111
133
112
- if ( event . toState === 'visible' ) {
134
+ if ( event . toState . startsWith ( 'visible' ) ) {
113
135
// Note: we shouldn't use `this` inside the zone callback,
114
136
// because it can cause a memory leak.
115
137
const onEnter = this . onEnter ;
116
-
117
138
this . _ngZone . run ( ( ) => {
118
139
onEnter . next ( ) ;
119
140
onEnter . complete ( ) ;
@@ -134,7 +155,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
134
155
135
156
/** Begin animation of the snack bar exiting from view. */
136
157
exit ( ) : Observable < void > {
137
- this . animationState = 'complete ' ;
158
+ this . animationState = 'hidden ' ;
138
159
return this . _onExit ( ) ;
139
160
}
140
161
0 commit comments