ionic-team / ionic-team/ionic-framework
bug: backdropDismiss: false prevents hardware back button/Esc from dismissing overlay
- Lenguaje dominante
- TypeScript
- Estrellas
- 52.7k
- Forks
- 13.3k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 51
Descripción
### Prerequisites
- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.
### Ionic Framework Version
- [X] v4.x
- [X] v5.x
- [X] v6.x
### Current Behavior
On v5, this following lines of code were implemented for overlays:
```ts
// handle back-button click
doc.addEventListener('ionBackButton', ev => {
const lastOverlay = getOverlay(doc);
if (lastOverlay && lastOverlay.backdropDismiss) {
(ev as BackButtonEvent).detail.register(OVERLAY_BACK_BUTTON_PRIORITY, () => {
return lastOverlay.dismiss(undefined, BACKDROP);
});
}
});
```
[found in](https://github.com/ionic-team/ionic-framework/blob/v6.0.7/core/src/utils/overlays.ts#:~:text=%7D-,//%20handle%20back%2Dbutton%20click,%7D\)%3B,-//%20handle%20ESC%20to)
Which seems to be a fix for what used to happen in v4, where none of the overlays would intercept the `ionBackButton` event.
The problem is that the event is only being intercepted here when the prop `backdropDismiss` is set to `true`, meaning that, for example when you have a loading overlay which should not be closed by pressing the hardware back button, since the event won't be intercepted it will go through with it's following event handlers (e.g. going back to the previous stack in navigation).
### Expected Behavior
I believe the expected behavior would be to intercept all events regardless of the prop `backdropDismiss`.
### Steps to Reproduce
1. Create a regular ionic app.
2. Navigate to a new a path (to add something to the stack).
2. Add a loading to it that doesn't close.
3. On Android, press the hardware back button.
4. It pop back to the previous stack.
### Code Reproduction URL
_No response_
### Ionic Info
Ionic:
Ionic CLI : 5.4.16 (C:\Users\Usuario\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 5.8.1
@angular-devkit/build-angular : 12.2.13
@angular-devkit/schematics : 12.2.13
@angular/cli : 12.2.0
@ionic/angular-toolkit : 4.0.0
Cordova:
Cordova CLI : 10.0.0
Cordova Platforms : android 9.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, cordova-plugin-ionic 5.5.1, (and 18 other plugins)
Utility:
cordova-res (update available: 0.15.4) : 0.15.3
native-run (update available: 1.5.0) : 1.4.0
System:
NodeJS : v14.17.0 (C:\Program Files\nodejs\node.exe)
npm : 8.4.1
OS : Windows 10
### Additional Information
The final code should be along the lines of:
```ts
// handle back-button click
doc.addEventListener('ionBackButton', ev => {
const lastOverlay = getOverlay(doc);
if (lastOverlay) {
(ev as BackButtonEvent).detail.register(OVERLAY_BACK_BUTTON_PRIORITY, () => {
if (lastOverlay.backdropDismiss) {
return lastOverlay.dismiss(undefined, BACKDROP);
}
});
}
});
```
Edit: While skimming through the code it seemed like this was introduced on v5, but looking back, this has been there since v4.
Guía de contribución
Línea de trabajo
Start in core/src/utils/overlays.ts at the ionBackButton listener linked in the issue. Check how overlay back-button priority registration currently depends on backdropDismiss, then verify that registration still intercepts the event while dismissal remains conditional. Reproduce the loading-overlay scenario on Android and confirm the navigation stack no longer pops.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- android, angular, typescript
- Área
- mobile
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100