Ionic 4-在平台硬件后退按钮android上关闭或关闭Modal [英] Ionic 4 - Dismiss or close Modal on platform hardware back button android
问题描述
在ionic 4中,按下硬件后退按钮时,我要关闭或消除将出现的任何模式. 我使用了下面给出的代码,即使前面的模态被取消,条件"if(modal){modal.dismiss();}"也总是得到满足
In ionic 4, on hardware back button press I want to close or dismiss any modal that will be present. I have used the below given code, here the condition "if(modal) { modal.dismiss(); }" always get satisfied even if previous modal are dismissed
constructor(private platform: Platform, private modalCtrl: ModalController) {
this.initializeapp();
}
initializeapp() {
this.platform.registerBackButtonAction(1, async () => {
const modal = await this.modalCtrl.getTop();
if (modal) {
modal.dismiss();
}
});
}
推荐答案
进行了一些挖掘,并且Ionic注册了一个自定义事件ionBackButton
来处理对硬件后退按钮的按下:
Did some digging around and Ionic registers a custom event ionBackButton
for handling the hardware back button press:
并且管理Ionic中所有叠加的叠加代码通过消除最上面的叠加来处理此ionBackButton
事件:
And the overlay code that manages all overlays in Ionic handles this ionBackButton
event by dismissing the topmost overlay:
那么您的代码想要实现什么?
So what is your code trying to achieve?
似乎只有在backdropDismiss
也设置为true时,它才会这样做:
It seems that it only does this when backdropDismiss
is also set to true:
if (lastOverlay && lastOverlay.backdropDismiss) {
我认为这意味着它被分类为可选/低级叠加层,而不是模拟模态.
Which I assume means that it's classed as an optional/low-grade overlay, rather than simulating a modal.
这篇关于Ionic 4-在平台硬件后退按钮android上关闭或关闭Modal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!