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

Ability to disable returning to a previous tab when a hardware back button is pressed #7263

Closed
mnasyrov opened this issue Jul 11, 2016 · 3 comments

Comments

@mnasyrov
Copy link

Short description of the problem:

An application has root tab-based navigation. When a hardware back button is pressed a previous tab is selected until selection history is empty, only after that the application is exited.

What behavior are you expecting?

A way to disable current behaviour for a particular case: when a hardware back button is pressed then an application is exited immediate regardless of tab selection history.

Which Ionic Version?
v2 (2.0.0-beta.10)

@JustinPierce
Copy link

Our Android testers noticed this behavior immediately and thought it was a bug in the app. We would also like the option for the back button to pop the navigation stack rather than go to the previous tab.

@elless
Copy link

elless commented Aug 15, 2016

We had the same issue. Currently, we are handling this by having the root pages of the tabs extend from this base class:

/**
 * Base class of a root page of a tab
 */
export abstract class BaseRootTabPage {
    private static HANDLER_PRIORITY = 100;  // Number bigger than 0 which is the default priority for cordova
    private isAndroid: boolean;
    private unregisterFunction: Function;

    constructor(protected platform: Platform,
        protected tab: Tab,
        protected app: App) {
        this.isAndroid = platform.is(Constants.Platforms.ANDROID);
    }

    ionViewWillEnter(): void {
        if (this.isAndroid) {
            this.unregisterFunction = this.platform.registerBackButtonAction(() => {

                // tab.getActive() == null when a view is being presented, otherwise it is defined
                if (this.tab.getActive()) {
                    // When on a root page of a tab while no view is presented - exit app
                    this.platform.exitApp();
                } else {
                    // When a view is being presented - pop that view
                    this.app.navPop();
                }
            }, BaseTabPage.HANDLER_PRIORITY);
        }
    }

    ionViewWillLeave(): void {
        if (this.isAndroid) {
            this.unregisterFunction();
        }
    }
}

@jgw96
Copy link
Contributor

jgw96 commented Aug 15, 2016

Hello all! Thanks for using Ionic! Since we are going to use this issue as a tracking issue for this and other back button issues on Android i will be closing this issue as a duplicate. Thanks for using ionic!

@jgw96 jgw96 closed this as completed Aug 15, 2016
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants