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

bug: controller getTop() method returns overlays that are not presented #19111

Closed
damirarh opened this issue Aug 16, 2019 · 2 comments
Closed
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@damirarh
Copy link

Bug Report

Ionic version:

[x] 4.7.4

Current behavior:
The call to LoadingController.getTop() returns the most recently created loading overlay even if it hasn't been presented/opened yet.

Expected behavior:
According to the docs,, the call to LoadingController.getTop() should only return a loading overlay if it has already been presented/opened.

Steps to reproduce:

  1. Create a loading overlay and present it.
  2. Create another loading overlay, but don't present it.
  3. LoadingController.getTop() returns the second overlay instead of the first one.
  4. LoadingController.dismiss() doesn't dismiss the open loading overlay and returns false.

Related code:

https://github.com/damirarh/ioni4-loading-ctrl

this.loadingCtrl.create({message: 'presented'}).then(loader => {
  loader.present().then(() => {
    this.loadingCtrl.create({message: 'created'}).then(() => {
      this.loadingCtrl.getTop().then(topLoader => {
        console.log(topLoader.message); // outputs 'created' instead of 'presented'
        this.loadingCtrl.dismiss().then(dismissed => {
          console.log(dismissed); // doesn't dismiss the open loading overlay and outputs 'false'
        });
      });
    });
  });
});

Other information:
This behavior also makes it impossible to reliably close all opened loading overlays without having a reference to each opened instance (i.e. reimplement the behavior of dismissAll in Ionic 3) because there's no way to get to the previously opened loading overlay using the LoadingController if an opened loading overlay was created afterward. I blogged about my attempt at implementing dismissAll in Ionic 4.

Ionic info:

Ionic:

   Ionic CLI                     : 5.2.2 (C:\Users\damir\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.7.4
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.0.0

Utility:

   cordova-res : not installed
   native-run  : 0.2.7

System:

   NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.9.0
   OS     : Windows 10
@ionitron-bot ionitron-bot bot added the triage label Aug 16, 2019
@liamdebeasi
Copy link
Contributor

liamdebeasi commented Sep 17, 2021

Thanks for the issue. I can reproduce this behavior. The problem here is that getOverlay, the function that getTop calls does not take into consideration whether or not an overlay is presented: https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/overlays.ts#L233-L236. This issue impacts all overlays.

This may have been intentional, but I think getTop implies getting the top overlay that is visible on the screen.

@liamdebeasi liamdebeasi changed the title bug: LoadingController.getTop() returns a non-opened loading overlay bug: controller getTop() method returns overlays that are not presented Sep 17, 2021
@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Sep 17, 2021
@ionitron-bot ionitron-bot bot removed the triage label Sep 17, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Feb 10, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests

2 participants