ionic-team / ionic-team/ionic-framework

bug: backdropDismiss: false prevents hardware back button/Esc from dismissing overlay

未关闭
#24,794 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
package: core type: bug
主要语言
TypeScript
星标
52.7k
派生
13.3k
平均合并
1 天 14 小时
30 天内合并 PR
50

描述

### 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.

贡献指南

打开贡献指南

调研方向

从 core/src/utils/overlays.ts 中 issue 链接到的 ionBackButton listener 开始。检查 overlay 返回按钮优先级注册当前如何依赖 backdropDismiss,然后验证该注册仍会拦截事件,同时关闭操作仍然是有条件的。在 Android 上复现 loading-overlay 场景,并确认 navigation stack 不再弹出。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, angular, typescript
领域
mobile
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。