Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Android can't handle back button on $ionicLoading #3272

Closed
morinted opened this issue Mar 10, 2015 · 5 comments
Closed

feat: Android can't handle back button on $ionicLoading #3272

morinted opened this issue Mar 10, 2015 · 5 comments
Assignees

Comments

@morinted
Copy link

Type: feat

Platform: android 4.4 webview

Issue #1273 addresed the fact that $ionicPlatform.registerBackButtonAction would fire while $ionicLoading was present.

However, I have a use-case where I would like to allow the user to cancel an $http request if they hit the back button. Would it be possible to add an option to $ionicLoading to allow the back button to be registered while it is open?

@morinted
Copy link
Author

After further reading the Ionic docs, I found that $ionicPlatform.onHardwareBackButton does not follow this same rule. For now, I will use this to cancel my loading screens. If this is the expected behavior, then the issue may be closed.

@mhartington
Copy link
Contributor

You can hide the loader with the hardware back button, it just need to execute at a higher priority level.

http://codepen.io/mhartington/pen/KwrvwZ

angular.module('ionicApp', ['ionic'])

  .controller('MyCtrl', function($scope,$ionicPlatform,$ionicLoading) {
  var callback = function(){
    $ionicLoading.hide();
  };
  var priority = 600;
  var deregister = $ionicPlatform.registerBackButtonAction(callback, priority);
  $scope.$on('$destroy', deregister)
  $ionicLoading.show();
});

@morinted
Copy link
Author

That works well, cheers.

On Mon, Mar 16, 2015 at 2:08 PM, Mike Hartington [email protected]
wrote:

You can hide the loader with the hardware back button, it just need to
execute at a higher priority level.

http://codepen.io/mhartington/pen/KwrvwZ


Reply to this email directly or view it on GitHub
#3272 (comment).

@Fayozjon
Copy link

morinted

http://wenxuebu.com/videokurs_schet

16.03.2015, 21:09, "morinted" [email protected]:That works well, cheers.

On Mon, Mar 16, 2015 at 2:08 PM, Mike Hartington <>
wrote:

You can hide the loader with the hardware back button, it just need to
execute at a higher priority level.


Reply to this email directly or view it on GitHub
<>.

—Reply to this email directly or .

@coolara
Copy link

coolara commented Nov 7, 2016

when 600 priority and 101 priority appear at the same time
101 priority is not work ,
how can i let the two registerBackButtonAction work at the same time

$ionicPlatform.registerBackButtonAction(function (e) {
      e.preventDefault();
      console.log('$location.path:----');
      console.log($location.path());
      console.log('$ionicHistory.backView url:-----');
      if ($ionicHistory.backView()) {
        console.log($ionicHistory.backView().url);
      } else {
        console.log($ionicHistory.backView());
      }
      if ($location.path() == '/home') {
        if ($rootScope.backButtonPressedOnceToExit) {
          ionic.Platform.exitApp();
        } else {
          $rootScope.backButtonPressedOnceToExit = true;
          $cordovaToast.showShortCenter('再按一次退出客户端');
          setTimeout(function () {
            $rootScope.backButtonPressedOnceToExit = false;
          }, 2000);
        }
      } else {
        var openPopup = function(type){
          var confirmPopup = $ionicPopup.confirm({
            template: '数据未保存,确定离开?',
            cancelText:'取消',
            okText:'确定'
          });

          confirmPopup.then(function(res) {
            if(res) {
              confirmPopup.close();
              if(type == 0){
                $ionicHistory.goBack()
              }else{
                $state.go('commodityManagement')
              }
            }
          });
        }
        if ($ionicHistory.backView()) {

          if($rootScope.newGoodsBroadcast && $location.path() == '/goodsInfo'){
            openPopup();
          }else if($location.path() == '/newSuppliers'){
            openPopup(0);
          }else if($location.path() != '/login'){
            $ionicHistory.goBack();
          }
          console.log('$location.path:----');
          console.log($location.path());
        }else {
          ionic.Platform.exitApp();
        }
      }

      return false;
    }, 101);
$ionicPlatform.registerBackButtonAction(function (e) {
       $ionicLoading.hide();
},600)

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants