$ ionicModal打开后硬件后退按钮不起作用? [英] hardware back button doesn't work after $ionicModal is opened?

查看:266
本文介绍了$ ionicModal打开后硬件后退按钮不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图覆盖硬件后退按钮功能。
所以,下面的代码一切正常。

i m trying to override hardware back button functionality. so,everything works fine with below code.

但是,我的应用程序中有两个$ ionicModal。当$ ionicModal打开和关闭。硬件后退按钮停止工作,应用程序无法用后退按钮关闭?
甚至没有调用$ ionicPlatform.registerBackButtonAction函数。

but,there are two $ionicModal in my app. As $ionicModal is opened and closed.Hardware back button stops working,app cannot closed with back button? Not even $ionicPlatform.registerBackButtonAction function is been called.

  $state.$current.name == "";
var backbutton=0;
    $ionicPlatform.registerBackButtonAction(function (event) {

        if (($state.$current.name == "app.intro") ||
            ($state.$current.name == "app.main.home") ||
            ($state.$current.name == "app.account") ||
            ($state.$current.name == "app.myBusiness")||
            ($state.$current.name == "app.support")||
            ($state.$current.name == "app.noConnection")) {
            if(backbutton==0){
                backbutton++;
                window.plugins.toast.showLongBottom('Press again to exit');
                $timeout(function(){backbutton=0;},3000);
            }else{
                navigator.app.exitApp();
                 }
            console.log("one");
        }else if($state.$current.name == "app.welcome.takeControl") {
            console.log("two");
                $state.go("app.main.home");
        }else{
            console.log("three");
                navigator.app.backHistory();
              }
    }, 100);

谢谢..

推荐答案

首先检查正在打开的离子模态实例是否被正确删除。如果您打开两次相同的模态实例但只关闭一次,则可能会出现后退按钮问题。因此,模态的一个实例可能尚未清理。

First check whether ionic modal instances which are opening are properly getting removed are not. Back button issue may occur if you are opening same modal instance twice but closing only once. So one instance of modal may not yet cleaned up.

在这种情况下,硬件后退按钮将尝试关闭每次尚未清理的模态,而不是转到上一个视图。由于'Dismiss modal'的优先级(200)高于'返回上一个视图'(100)。

In this case Hardware back button will try to Dismiss modal which is not yet cleaned up for each time rather than going to previous view. Since 'Dismiss modal' has higher priority(200) than 'Return to previous view'(100).

registerBackButtonAction的优先级如下:

The priorities for the registerBackButtonAction are as follows:


  • 返回上一个视图= 100

  • 关闭侧菜单= 150

  • 解雇模式= 200

  • 关闭操作表= 300

  • 关闭popup = 400

  • 关闭加载重叠= 500

  • Return to previous view = 100
  • Close side menu = 150
  • Dismiss modal = 200
  • Close action sheet = 300
  • Dismiss popup = 400
  • Dismiss loading overlay = 500

了解更多关于$ ionicModal的信息

了解更多关于$ ionicPlatform.registerBackButtonAction 的信息

这篇关于$ ionicModal打开后硬件后退按钮不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆