Android back button in modal


#1

Hi guys,
Is it normal that the Android back button doesn’t close the modal but goes back in the app ?

I thought modal.present() added the modal to the history so that the return button would close the modal.
What am I missing here ?


#2

In my case, all the modals close using the back button, but only one modal goes back to the app. Which is what I want to see in all cases. Looking forward to any comments on this behaviour!


#3

Yes it’s normal, it’s bugged.


#4

So in my app, I have modals and pages. With the hard back button, I would like them all to go one step back (off course :)) Here’s the code I came up so far. Any ideas to bullet proof the back button?

import { Component, ViewChild} from '@angular/core';
import { Platform, Nav, ViewController } from 'ionic-angular';
import './rxjs-operators';
import { StatusBar } from 'ionic-native';

import { HomePage } from '../pages/home/home';


@Component({
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})

export class MyApp {
  // First page to push onto the stack
  rootPage = HomePage;
  @ViewChild(Nav) nav: Nav;
  @ViewChild(ViewController) viewCtrl: ViewController;

  constructor(platform: Platform ) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.hide(); 
      platform.registerBackButtonAction(() => { //android devices can go back with hard back button
            console.log('back button pressed');
            if(this.nav.canGoBack()) {
              console.log('nav can go back');
              this.nav.pop();
            } else if (this.viewCtrl._didEnter() ) { 
                console.log('ViewController can be dismissed');
                this.viewCtrl.dismiss();
             }
        }, 100);
    });
  }
}