Ionic-framework: Platform.backButton.subscribeWithPriority doesn't manage priorities

Created on 19 Mar 2019  路  8Comments  路  Source: ionic-team/ionic-framework

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 ([email protected])
   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

core bug

Most helpful comment

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.

All 8 comments

Hi there,

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

Thanks!

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.

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!

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.

Thanks for the issue. This has been resolved via https://github.com/ionic-team/ionic/pull/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!

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(); });

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

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.

Was this page helpful?
0 / 5 - 0 ratings