Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49248

Back Button Hardware Event Handler Can't Determine Overlay Views

$
0
0

@OliverPrimo wrote:

Hello Everyone,

I modified the functionality of hardware back button. It works on pages but it cannot determine whether an overlay views like modals and alert dialog boxes are present or not.

Here is my code

    this.platform.registerBackButtonAction(() => { 
      let nav = app._appRoot._getActivePortal() || app.getActiveNav();
      let activeView = nav.getActive().instance;

      if (activeView != null) {
        if (nav.canGoBack()) {
            if (activeView instanceof MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree ||) {
                // do something
            } else {
	           nav.pop();
            }
        } else if (activeView.isOverlay) {
          activeView.dismiss();
        } else {
          let alert = this.alertCtrl.create({
            title: 'Ionic App',
            message: 'Do you want to close the app?',
            buttons: [{
              text: 'Cancel',
              role: 'cancel',
              handler: () => {
                console.log('Application exit prevented!');
              }
            },
            {
              text: 'Close',
              handler: () => {
                this.platform.exitApp();
              }
            }]
          });
          alert.present();
        }
      }
    });

I hope someone can help me with this :slight_smile:

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49248

Trending Articles