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

hardware back button doesn't dismiss ActionSheet overlay #10168

Closed
brettatoms opened this issue Jan 25, 2017 · 18 comments
Closed

hardware back button doesn't dismiss ActionSheet overlay #10168

brettatoms opened this issue Jan 25, 2017 · 18 comments
Assignees
Labels
ionitron: v3 moves the issue to the ionic-v3 repository
Milestone

Comments

@brettatoms
Copy link

Ionic version: (check one with "x")
[ ] 1.x
[x] 2.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
The hardware back button doesn't dismiss an ActionSheet on Android.

Expected behavior:
Tapping the hardware back button while an ActionSheet is currently visible would dismiss the ActionSheet.

Steps to reproduce:

  1. Open action sheet.
  2. Tap hardware back button

Related code:

Quick and dirty fix is:

    this.platform.registerBackButtonAction(() => {
      const overlayView = this.app._appRoot._overlayPortal._views[0];
      if (overlayView && overlayView.dismiss) {
        overlayView.dismiss();
      } else {
        this.app.goBack();
      }
    }, 0);

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.6
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.0.0
ios-deploy version: 1.9.0
ios-sim version: 5.0.9
OS: OS X El Capitan
Node Version: v6.9.1
Xcode version: Xcode 8.2.1 Build version 8C1002
@jgw96 jgw96 added the v2 label Jan 25, 2017
@jgw96
Copy link
Contributor

jgw96 commented Jan 25, 2017

Thanks for opening an issue with us! We will look into this! (:

@jgw96 jgw96 added needs: reply the issue needs a response from the user and removed needs: reply the issue needs a response from the user labels Jan 25, 2017
@manucorporat manucorporat self-assigned this Jan 25, 2017
@jgw96
Copy link
Contributor

jgw96 commented Jan 25, 2017

I can confirm that this is how native android works.

@manucorporat
Copy link
Contributor

yes, I disabled this feature, because the way it was implemented was kind of buggy. It is in my roadmap to refactor it

@daveshirman
Copy link

This is NOT how native Android works. It was a deliberate decision mentioned in a recent release to disable the back button for ActionSheet and overlays, waiting for refactoring.

@jgw96
Copy link
Contributor

jgw96 commented Jan 26, 2017

Sorry @daveshirman , i meant that i can confirm that on native android you can close the actionsheet with the back button

@daveshirman
Copy link

@jgw96 Sorry, my bad! We're all good.

@Ronald-13
Copy link

Also, It would be nice to get the control of the pop up which are initiated from html, so that we can dismiss them programatically.

@lepetitpaco
Copy link

Can you disable completly the back button on all pages of the application ?
If yes, where, how ?

@Ronald-13
Copy link

Ronald-13 commented Feb 20, 2017

@davidgennaoui Yes, you can disable backbutton action entirely.

//app.component.ts
import { Platform } from 'ionic-angular';
export class MyApp {
constructor(public platform: Platform){
}
backButtonController() {
this.deregisterBackButtonAction = this.platform.registerBackButtonAction(() => {
//perform actions when backbutton is pressed
}, 1);
}

ngOnDestroy() {
this.deregisterBackButtonAction();
}
}

@manucorporat manucorporat added this to the 2.4.0 milestone Mar 16, 2017
@manucorporat manucorporat modified the milestones: 3.0, 3.1 Apr 5, 2017
@Muji86
Copy link

Muji86 commented Apr 13, 2017

@jgw96 this is also an issue on Alerts

@alexnu
Copy link

alexnu commented Jun 27, 2017

Hi,

So is this going to be fixed?

@AmitMY
Copy link
Contributor

AmitMY commented Aug 10, 2017

@manucorporat Just created a simple fix for overlays, like alerts, popover, etc..

@lostdev
Copy link

lostdev commented Aug 24, 2017

Looking forward to seeing this fixed. User experience is a little dodgy due to this.

@PabloJC
Copy link

PabloJC commented Feb 15, 2018

This fix work for me:

import { IonicApp } from 'ionic-angular';

closeModals(){
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();

if (activePortal) {
  activePortal.dismiss();
}

}

It helps me to close datetimes, bottonsheet, dialogs and other modals

@Muji86
Copy link

Muji86 commented Feb 15, 2018

Thanks @PabloJC
I'll try this solution.
How is closeModals() invoked?

@PabloJC
Copy link

PabloJC commented Feb 15, 2018

I have created in AppComponent a function that makes me logout in the app when time expires. At that moment I call the closeModals function. For example:

this.logoutTimeout = setTimeout(() => {

  if (this.nav.getActive().component.name !== 'LoginPage') {
    this.closeModals()
    this.logout();
  }

}, 5 * 60000);

@adamdbradley adamdbradley added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 1, 2018
@imhoffd imhoffd removed ionitron: v3 moves the issue to the ionic-v3 repository labels Nov 28, 2018
@Ionitron Ionitron added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 28, 2018
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know!

Thank you for using Ionic!

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

Issue moved to: ionic-team/ionic-v3#169

@ionitron-bot ionitron-bot bot closed this as completed Nov 28, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ionitron: v3 moves the issue to the ionic-v3 repository
Projects
None yet
Development

No branches or pull requests