Skip to content
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

feat: resolve overlay present method early when dismissing during enter animation #29261

Open
3 tasks done
rbalet opened this issue Apr 3, 2024 · 4 comments
Open
3 tasks done
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@rbalet
Copy link

rbalet commented Apr 3, 2024

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

If I close the modal to quickly, the onWillDismiss() will never occur.

Expected Behavior

Working as if I would close the modal normally

Steps to Reproduce

<ion-button (click)="openModal()">Test modal</ion-button>
  async openModal() {
    const modal = await this._modalController.create({
      component: Tab2Page,

      cssClass: 'modal-alert-component',
    });

    await modal.present();

    const response = await modal.onWillDismiss();

    console.log('response', response);
  }
  1. Open the chrome dev tool under the console element
  2. Click on the Test modal
  3. Click on escape button of your keyboard directly after opening it
  4. response Won't be logged, as the onWillDismiss() is not triggered.

Code Reproduction URL

https://github.com/rbalet/error-on-will-dismiss

Ionic Info

Ionic:

Ionic CLI : 7.1.1 (/opt/homebrew/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 7.8.2
@angular-devkit/build-angular : 17.3.3
@angular-devkit/schematics : 17.3.3
@angular/cli : 17.3.3
@ionic/angular-toolkit : 11.0.1

Capacitor:

Capacitor CLI : 5.7.4
@capacitor/android : not installed
@capacitor/core : 5.7.4
@capacitor/ios : not installed

Utility:

cordova-res : not installed globally
native-run : 2.0.1

System:

NodeJS : v20.11.0 (/usr/local/bin/node)
npm : 10.2.4
OS : macOS Unknown

Additional Information

No response

@sean-perkins
Copy link
Contributor

Hello @rbalet thanks for reporting this issue! Can you make your reproduction public?

@sean-perkins sean-perkins added the needs: reply the issue needs a response from the user label Apr 3, 2024
@ionitron-bot ionitron-bot bot removed the triage label Apr 3, 2024
@rbalet
Copy link
Author

rbalet commented Apr 3, 2024

@sean-perkins done

Sorry I though I did '^^

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Apr 3, 2024
@sean-perkins
Copy link
Contributor

Hello @rbalet, thanks for making the repository public!

As a workaround you can update your usage to:

async openModal() {
  const modal = await this._modalController.create({
    component: Tab2Page,

    cssClass: 'modal-alert-component',
  });

  modal.present();

  const response = await modal.onWillDismiss();

  console.log('response', response);
}

By awaiting modal.present() you were blocking execution until the modal was fully presented. This means when dismissing the modal before the animation completes, the lifecycle event is emitted before the onWillDismiss is registered.

I think this is an area we could explore resolving the present promise early if the user dismisses the overlay during the animation to simplify the developer experience.

I'm going to capture this as a feature request 👍

@sean-perkins sean-perkins changed the title bug: HTMLIonModalElement.onWillDismiss() isn't triggered if close happen to fast feat: resolve overlay present method early when dismissing during enter animation Apr 5, 2024
@sean-perkins sean-perkins added type: feature request a new feature, enhancement, or improvement package: core @ionic/core package labels Apr 5, 2024
@ionitron-bot ionitron-bot bot removed triage labels Apr 5, 2024
@sean-perkins sean-perkins removed their assignment Apr 5, 2024
@rbalet
Copy link
Author

rbalet commented Apr 5, 2024

Makes a lot of sense, thx for the explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

2 participants