Ionic 3:后退按钮硬件事件处理程序无法确定叠加视图
Ionic 3: Back Button Hardware Event Handler Can't Determine Overlay Views
我有一个 ionic 3 应用程序,我修改了硬件后退按钮的功能。它适用于页面,但无法确定是否存在模态和警报对话框等叠加视图。
这是我的代码
this.platform.registerBackButtonAction(() => {
let nav = app._appRoot._getActivePortal() || app.getActiveNav();
let activeView = nav.getActive().instance;
if (activeView != null) {
if (nav.canGoBack()) {
if (activeView instanceof MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree) {
// do something
} else {
nav.pop();
}
} else if (activeView.isOverlay) {
activeView.dismiss();
} else {
let alert = this.alertCtrl.create({
title: 'Ionic App',
message: 'Do you want to close the app?',
buttons: [{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Application exit prevented!');
}
},
{
text: 'Close',
handler: () => {
this.platform.exitApp();
}
}]
});
alert.present();
}
}
});
我希望有人能帮助我解决这个问题。提前谢谢你
声明一个变量:viewController:ViewController
然后在您的页面或 app.components.ts 中,将您的后退按钮句柄修改为类似于
this.platform.registerBackButtonAction(() => {
try{
this.viewController.dismiss()
}
catch(e){
console.log("error");
}
});
我用MD解决了。 Riyas 在这里的回答:
我有一个 ionic 3 应用程序,我修改了硬件后退按钮的功能。它适用于页面,但无法确定是否存在模态和警报对话框等叠加视图。
这是我的代码
this.platform.registerBackButtonAction(() => {
let nav = app._appRoot._getActivePortal() || app.getActiveNav();
let activeView = nav.getActive().instance;
if (activeView != null) {
if (nav.canGoBack()) {
if (activeView instanceof MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree) {
// do something
} else {
nav.pop();
}
} else if (activeView.isOverlay) {
activeView.dismiss();
} else {
let alert = this.alertCtrl.create({
title: 'Ionic App',
message: 'Do you want to close the app?',
buttons: [{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Application exit prevented!');
}
},
{
text: 'Close',
handler: () => {
this.platform.exitApp();
}
}]
});
alert.present();
}
}
});
我希望有人能帮助我解决这个问题。提前谢谢你
声明一个变量:viewController:ViewController
然后在您的页面或 app.components.ts 中,将您的后退按钮句柄修改为类似于
this.platform.registerBackButtonAction(() => {
try{
this.viewController.dismiss()
}
catch(e){
console.log("error");
}
});
我用MD解决了。 Riyas 在这里的回答: