【问题标题】:ionic 4 deal with modal when users click phone back button当用户单击手机后退按钮时,ionic 4 处理模态
【发布时间】:2019-10-08 11:33:35
【问题描述】:

当用户点击手机的返回按钮时会发生什么?模态打开时的情况。

注册了一个后退按钮:

// To prevent interference with ionic's own backbutton handling
// you can subscribe with a low priority instead
this.platform.backButton.subscribe(() => {
  // code that is executed when the user pressed the back button
  // and ionic doesn't already know what to do (close modals etc...)
  self.modalController.dismiss();
});

代码的问题:

  • 关闭/关闭模式没问题!

  • 但它也将打开模式的页面推回。意味着它弹出模态页面后面的页面。

这不应该发生页面不应该弹出 - 只有模式应该关闭。

检查添加的图像 gif -> Click here to see the problem

【问题讨论】:

  • 在代码末尾你可以尝试返回false;
  • 不工作!同样的问题。
  • 你找到解决办法了吗?
  • 你找到解决办法了吗?

标签: ionic-framework ionic4 ionic-native


【解决方案1】:

您可以考虑使用具有高优先级的platform.backButton.subscribeWithPriority()(例如:9999)。

然后检查是否有modalController.getTop()打开的模态。

constructor(private modalCtrl: ModalController, private nav: NavController) { 
}

ngOnInit() {
  this.platform.backButton.subscribeWithPriority(9999, () => {
    this.closeModalOrPage();
  });
}

async closeModalOrPage(){
  let modal = await this.modalCtrl.getTop();
  if (modal){
    modal.dismiss();
  } else {
    this.nav.pop();
  }
}

【讨论】:

    猜你喜欢
    • 2020-01-12
    • 2019-01-13
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多