Skip to content

Commit

Permalink
fix(toast): dismiss timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 24, 2018
1 parent e20f76c commit 44f343d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/src/components/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import mdLeaveAnimation from './animations/md.leave';
})
export class Toast implements OverlayInterface {

private durationTimeout: any;

presented = false;

@Element() el: HTMLElement;
Expand Down Expand Up @@ -142,19 +144,22 @@ export class Toast implements OverlayInterface {
* Present the toast overlay after it has been created.
*/
@Method()
present(): Promise<void> {
return present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position).then(() => {
if (this.duration) {
setTimeout(() => this.dismiss(), this.duration);
}
});
async present(): Promise<void> {
await present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position);

if (this.duration > 0) {
this.durationTimeout = setTimeout(() => this.dismiss(), this.duration);
}
}

/**
* Dismiss the toast overlay after it has been presented.
*/
@Method()
dismiss(data?: any, role?: string): Promise<void> {
if (this.durationTimeout) {
clearTimeout(this.durationTimeout);
}
return dismiss(this, data, role, 'toastLeave', iosLeaveAnimation, mdLeaveAnimation, this.position);
}

Expand Down

0 comments on commit 44f343d

Please sign in to comment.