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

Platform.backButton.subscribeWithPriority doesn't manage priorities #17824

Closed
TakkuzOld opened this issue Mar 19, 2019 · 8 comments
Closed

Platform.backButton.subscribeWithPriority doesn't manage priorities #17824

TakkuzOld opened this issue Mar 19, 2019 · 8 comments
Labels
package: core @ionic/core package type: bug a confirmed bug report
Milestone

Comments

@TakkuzOld
Copy link

Bug Report

Ionic version:
[x] 4.x

Current behavior:
The method subscribeWithPriority doesn't manage priority properly: it doesn't matter which priority I've set, it doesn't go back throught the stack. If I set a low priority it hides popups but still doesn't change page.

It seems a bug but there's any documentation for that method, so I don't know if I'm using it wrong or it's deprecated without any warning.

Expected behavior:
Like in previous Ionic versions I was expecting to leave back working properly for pages using correct priority level.

Steps to reproduce:
Create a blank app with Android platform, add a second page, and manage .backButton.subscribeWithPriority() inside app.component.ts

Related code:

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      this.platform.backButton.subscribeWithPriority(601, async () => {
        console.log('Back Pressed');
      })
    });
  }

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.12.0
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.12.4
   @angular-devkit/schematics    : 7.2.3
   @angular/cli                  : 7.2.4
   @ionic/angular-toolkit        : 1.3.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 8.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 13 other plugins)

System:

   Android SDK Tools : 26.1.1 (/opt/android-sdk)
   NodeJS            : v10.15.3 (/home/vittorio/.nvm/versions/node/v10.15.3/bin/node)
   npm               : 6.4.1
   OS                : Linux 4.18

@ionitron-bot ionitron-bot bot added the triage label Mar 19, 2019
@liamdebeasi
Copy link
Contributor

Hi there,

Thanks for opening an issue with us! Can you provide a repository with the code required to reproduce this issue?

Thanks!

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Mar 22, 2019
@ionitron-bot ionitron-bot bot removed the triage label Mar 22, 2019
@TakkuzOld
Copy link
Author

Hi, thank you.

I provided a repository with the code you need: https://github.com/Takkuz/backButtonIonicIssue

On tab2 there is a button to go to tab2-page2, on that page you can change dinamically the priority of the hardware backButton on Android. Using no value or <0 or NaN value removes the subscription.

As you can see, without subscription you can use hardware backButton to go to previous page; with priority 0 to 100 it closes popup, as expected, but you doesn't go to previous page; from 101 and above even the popup isn't handled anymore.

As far as I can remember, from previous Ionic versions, under priority 100 is handled only if there is any page on the stack because going back on page has priority 100.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Mar 26, 2019
@liamdebeasi
Copy link
Contributor

Hi there,

Thanks for the repo! I was able to reproduce this issue.

I have added this issue to our Hardware Back Button Issue Tracker. We will look into this!

Thanks for using Ionic!

@Ketec
Copy link

Ketec commented Jul 22, 2019

Being able to control your navigation stacks and clicks etc should be the absolute basics.
Yet this is open for 4 months.

It shouldn't have been out of beta or RC stage yet with this kind of bugs.

But now I'm stuck with it, people above are waiting for an explanation for delays and best I can tell them is "ionic has major bugs but they haven't fixed them".
And release is delayed again - which means financial impact.

@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #20613, and a fix will be available in an upcoming release of Ionic Framework.

Accompanying this fix is a new documentation page dedicated to using the hardware back button in Ionic Framework. These docs will ship alongside the fix.

In order to continue to process back button events, you will be able to call the processNextHandler function that is passed into all hardware back button callbacks. For example this would be the usage in Angular:

this.platform.backButton.subscribeWithPriority(10, (processNextHandler) => {
  console.log('Handler was called!');
    
  processNextHandler();
});

Thanks!

@camengadisaputra
Copy link

camengadisaputra commented May 19, 2020

Hi @liamdebeasi i got this warning when i try using processNextHandler

Argument of type '(processNextHandler: any) => Promise<void>' is not assignable to parameter of type '() => void | Promise<any>'

here how i using it
this.platform.backButton.subscribeWithPriority(10, async (processNextHandler) => { const modal = await this.modalController.getTop(); if (modal) { modal.dismiss(); } processNextHandler(); });

this.platform.backButton.subscribeWithPriority(-1, async (processNextHandler) => { if (!this.routerOutlet.canGoBack()) { App.exitApp(); } else { this.navController.back(); } processNextHandler(); });

@liamdebeasi
Copy link
Contributor

@camengadisaputra Please open a new issue with a code reproduction. Thanks!

@ionitron-bot
Copy link

ionitron-bot bot commented Jun 18, 2020

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 Jun 18, 2020
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

4 participants