mirror of
				https://github.com/ionic-team/ionic-framework.git
				synced 2025-11-04 13:17:56 +08:00 
			
		
		
		
	fix(toast): dismiss timeout
This commit is contained in:
		@ -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);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user