fix(toast): dismiss timeout

This commit is contained in:
Manu Mtz.-Almeida
2018-03-24 03:25:16 +01:00
parent e20f76c3b1
commit 44f343d3dc

View File

@ -22,6 +22,8 @@ import mdLeaveAnimation from './animations/md.leave';
}) })
export class Toast implements OverlayInterface { export class Toast implements OverlayInterface {
private durationTimeout: any;
presented = false; presented = false;
@Element() el: HTMLElement; @Element() el: HTMLElement;
@ -142,12 +144,12 @@ export class Toast implements OverlayInterface {
* Present the toast overlay after it has been created. * Present the toast overlay after it has been created.
*/ */
@Method() @Method()
present(): Promise<void> { async present(): Promise<void> {
return present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position).then(() => { await present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position);
if (this.duration) {
setTimeout(() => this.dismiss(), this.duration); if (this.duration > 0) {
} this.durationTimeout = setTimeout(() => this.dismiss(), this.duration);
}); }
} }
/** /**
@ -155,6 +157,9 @@ export class Toast implements OverlayInterface {
*/ */
@Method() @Method()
dismiss(data?: any, role?: string): Promise<void> { dismiss(data?: any, role?: string): Promise<void> {
if (this.durationTimeout) {
clearTimeout(this.durationTimeout);
}
return dismiss(this, data, role, 'toastLeave', iosLeaveAnimation, mdLeaveAnimation, this.position); return dismiss(this, data, role, 'toastLeave', iosLeaveAnimation, mdLeaveAnimation, this.position);
} }