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