-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(snack bar): Add enter and exit animations. #1320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7151d93
178323c
69a0ccf
eef6e54
5f3a35f
37cead1
d710b48
ccc2bdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class AnimationCurves { | ||
static STANDARD_CURVE = 'cubic-bezier(0.4,0.0,0.2,1)'; | ||
static DECELERATION_CURVE = 'cubic-bezier(0.0,0.0,0.2,1)'; | ||
static ACCELERATION_CURVE = 'cubic-bezier(0.4,0.0,1,1)'; | ||
static SHARP_CURVE = 'cubic-bezier(0.4,0.0,0.6,1)'; | ||
}; | ||
|
||
|
||
export class AnimationDurations { | ||
static COMPLEX = '375ms'; | ||
static ENTERING = '225ms'; | ||
static EXITING = '195ms'; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import {OverlayRef} from '../core'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import {Subject} from 'rxjs/Subject'; | ||
import {MdSnackBarContainer} from './snack-bar-container'; | ||
|
||
// TODO(josephperrott): Implement onAction observable. | ||
|
||
|
@@ -12,19 +13,28 @@ export class MdSnackBarRef<T> { | |
/** The instance of the component making up the content of the snack bar. */ | ||
readonly instance: T; | ||
|
||
/** The instance of the component making up the content of the snack bar. */ | ||
readonly containerInstance: MdSnackBarContainer; | ||
|
||
/** Subject for notifying the user that the snack bar has closed. */ | ||
private _afterClosed: Subject<any> = new Subject(); | ||
|
||
constructor(instance: T, private _overlayRef: OverlayRef) { | ||
constructor(instance: T, | ||
containerInstance: MdSnackBarContainer, | ||
private _overlayRef: OverlayRef) { | ||
// Sets the readonly instance of the snack bar content component. | ||
this.instance = instance; | ||
this.containerInstance = containerInstance; | ||
} | ||
|
||
/** Dismisses the snack bar. */ | ||
dismiss(): void { | ||
if (!this._afterClosed.closed) { | ||
this._overlayRef.dispose(); | ||
this._afterClosed.complete(); | ||
this.containerInstance.exit().subscribe(() => { | ||
this._overlayRef.dispose(); | ||
this._afterClosed.next(); | ||
this._afterClosed.complete(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
}); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,6 @@ import {MdSnackBarRef} from './snack-bar-ref'; | |
import {MdSnackBarContainer} from './snack-bar-container'; | ||
import {SimpleSnackBar} from './simple-snack-bar'; | ||
|
||
export {MdSnackBarRef} from './snack-bar-ref'; | ||
export {MdSnackBarConfig} from './snack-bar-config'; | ||
|
||
// TODO(josephperrott): Animate entrance and exit of snack bars. | ||
// TODO(josephperrott): Automate dismiss after timeout. | ||
|
||
|
||
|
@@ -45,14 +41,24 @@ export class MdSnackBar { | |
*/ | ||
openFromComponent<T>(component: ComponentType<T>, | ||
config: MdSnackBarConfig): MdSnackBarRef<T> { | ||
if (this._snackBarRef) { | ||
this._snackBarRef.dismiss(); | ||
} | ||
let overlayRef = this._createOverlay(); | ||
let snackBarContainer = this._attachSnackBarContainer(overlayRef, config); | ||
let mdSnackBarRef = this._attachSnackbarContent(component, snackBarContainer, overlayRef); | ||
|
||
// If a snack bar is already in view, dismiss it and enter the new snack bar after exit | ||
// animation is complete. | ||
if (this._snackBarRef) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment like // If there is already a snackbar open, dismiss it and open a new one
// only after the close animation is complete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
this._snackBarRef.afterDismissed().subscribe(() => { | ||
mdSnackBarRef.containerInstance.enter(); | ||
}); | ||
this._snackBarRef.dismiss(); | ||
// If no snack bar is in view, enter the new snack bar. | ||
} else { | ||
mdSnackBarRef.containerInstance.enter(); | ||
} | ||
this._live.announce(config.announcementMessage, config.politeness); | ||
return mdSnackBarRef; | ||
this._snackBarRef = mdSnackBarRef; | ||
return this._snackBarRef; | ||
} | ||
|
||
/** | ||
|
@@ -88,10 +94,7 @@ export class MdSnackBar { | |
overlayRef: OverlayRef): MdSnackBarRef<T> { | ||
let portal = new ComponentPortal(component); | ||
let contentRef = container.attachComponentPortal(portal); | ||
let snackBarRef = <MdSnackBarRef<T>> new MdSnackBarRef(contentRef.instance, overlayRef); | ||
|
||
this._snackBarRef = snackBarRef; | ||
return snackBarRef; | ||
return new MdSnackBarRef(contentRef.instance, container, overlayRef); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment explaining what the initial transform is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done