ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Android: Back button not dismissing modals

Open infinnie opened this issue 10 years ago • 76 comments

Short description of the problem:

I wrote an app with a modal that is expected to be dismissed with either its own “cancel” button or the hardware back button. However since an upgrade to Ionic 2.0.0 RC 1, it couldn’t be dismissed with the hardware button, but will quit within several presses with the modal present instead. If I manually dismiss the modal after pressing the back button, I could find that the page present is different from the one I opened the modal with, but some previous page.

Nor do hardware back buttons dismiss loading indicators.

What behavior are you expecting?

As in Ionic 2.0.0 Beta 10 and 11 (forgotten what happened on RC 0), the modal is dismissed with the hardware back button pressed.

Steps to reproduce:

  1. Write an app with a modal
  2. Build and run it
  3. Open that modal
  4. Press the hardware back button and see what would happen.

Which Ionic Version? 1.x or 2.x 2.0.0 RC 1

Run ionic info from terminal/cmd prompt: (paste output below)

Your system information: 

Cordova CLI: 6.3.0
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
OS:
Node Version: v6.3.1

Android 4.4.4

infinnie avatar Oct 14 '16 06:10 infinnie

i think it is related with modal not having a ion-nav of its own again.

comfortme avatar Oct 14 '16 07:10 comfortme

@comfortme What did you mean by “again”? Just curious.

infinnie avatar Oct 14 '16 07:10 infinnie

there are couple of issues about modals navigation and i think they might be related to yours. https://github.com/driftyco/ionic/issues/8151#issuecomment-252664109

comfortme avatar Oct 14 '16 08:10 comfortme

@manucorporat should this be fixed by your modal navigation stuff you working on? @infinnie could you provide a repo we could use to reproduce this issue? Thanks!

jgw96 avatar Oct 14 '16 15:10 jgw96

@jgw96 Just build anything that contains a modal for Android.

infinnie avatar Oct 14 '16 23:10 infinnie

Here is one example of register back button, that handles everything: https://github.com/driftyco/ionic/issues/6982#issuecomment-254740855

laserus avatar Oct 19 '16 07:10 laserus

@laserus That's not a solution though, that's a workaround. This is definitely a regression bug in the framework.

daveshirman avatar Oct 19 '16 09:10 daveshirman

@daveshirman yes and no. For modals it is a regression bug, for not-closing-menu-on-back-button it is how driftyco guys see it, for custom alert confirmation on particular pages it is not a bug, but customization (what the backbutton handler is in the first place for).

If you will need to have a custom back button you will end up with similar approach independently of weather there is a bug in modal or not. Unless ionic2 will have some more generic mixing action handling back button (current priority on back button actions does not work for this at all).

laserus avatar Oct 19 '16 09:10 laserus

I have the same issue when pushing a page onto the app root. I have a tabs application, and what seems to happen is that after pushing a page onto the root with this.app.getRootNav().push(NewPage); pressing the back button moves back through the previously selected tabs (in the background). Only after all the tab history is done, does the new page get dismissed, showing the first tab in the app.

moldstadt avatar Oct 19 '16 14:10 moldstadt

This has nothing to do with back button, but I'm also not able to dismiss the modal, I have issued this (https://github.com/driftyco/ionic/issues/8776) and created a demo repo, so anyone can have a loot at it, this is really a nightmare for us now.

dgroh avatar Oct 19 '16 19:10 dgroh

@dgroh That would be another thing.

infinnie avatar Oct 20 '16 00:10 infinnie

I can confirm that my modals are also not closing via the back-button, on a pretty vanilla (no plugins or JS/css customizations) RC.1 app.

Google Nexus 6. Android 6.0.1

lincolnthree avatar Oct 25 '16 17:10 lincolnthree

I can confirm this as well. Ionic 2 RC.1 on latest Android N.

martin-eberle avatar Oct 25 '16 17:10 martin-eberle

We are also experiencing this on Android. Any ideas on resolution @manucorporat or @jgw96?

Cordova CLI: 6.3.1
Gulp version:  CLI version 3.9.1
Gulp local:
Ionic Framework Version: 2.0.0-rc.1
Ionic CLI Version: 2.1.4
Ionic App Lib Version: 2.1.2
Ionic App Scripts Version: 0.0.36
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v6.8.0
Xcode version: Xcode 7.3.1 Build version 7D1014

dylanvdmerwe avatar Oct 25 '16 20:10 dylanvdmerwe

I can confirm this as well. Ionic 2 RC.1 on Android devices.

ghost avatar Oct 28 '16 06:10 ghost

Not fixed even in RC2…

infinnie avatar Nov 07 '16 01:11 infinnie

@manucorporat any ideas what may be causing this? Is this expected behavior with modals being separate from the main nav?

jgw96 avatar Nov 07 '16 10:11 jgw96

@jgw96 Certainly not, if you mean “conforming to the corresponding platform’s recommended behavior for apps” by “expected”. In native Android/WP apps, the hardware back button is intended to be used to dismiss modals if present. Popping up the underlying page without dismissing the modal only makes the whole app confusing.

infinnie avatar Nov 08 '16 06:11 infinnie

Same problem here. RC 2

jonatastrafaniuc avatar Nov 13 '16 00:11 jonatastrafaniuc

Same for me with RC 2.

Gp2mv3 avatar Nov 13 '16 17:11 Gp2mv3