Unregister back button action


#1

On my app, I have:
this.platform.registerBackButtonAction(this.backButtonAction.bind(this), 500);
Which does

private backButtonAction() {
        Vibration.vibrate(30);

        if (this.nav.canGoBack())
            this.nav.pop();
        else
            this.openPage(ProfilePage);
}

But this code does not dismiss modals, so I added in my modal:
this.platform.registerBackButtonAction(this.dismiss.bind(this), 600);

Which does indeed dismiss the modal on back button, but makes the other listener not to work (fair, lower priority).

Is there a way to unregister this action (when leaving the modal)?
I have another case where in the same page, you have a 3 steps progress, and when you are on step 2, I wan’t back button to go back to step 1. Without unregistering the listener I kind of can’t.

Thanks!


#2

This might be of use :slight_smile: Specifically the overlay bits, you can stick to only registering one back button action.


#3

Thanks! Very helpful indeed.


#4

@AmitMY according to the docs:

The call to registerBackButtonAction returns a function that deregisters the custom function you just registered. E.g.:

//...
modal.present().then(()=>{
    deregisterFunction = this.platform.registerBackButtonAction(()=>{
        customFunction();
        modal.onWillDismiss(()=>{deregisterFunction();});
    });
}); 
//...

a little late to the party, but I hope it helps anyone else that comes looking for an answer on this topic…