fix(backbutton): Allow only one back button listener to run per click, closes #693

This commit is contained in:
Adam Bradley
2014-03-06 15:16:49 -06:00
parent 78206d0e7c
commit a491f22c1f
7 changed files with 145 additions and 51 deletions

View File

@@ -26,25 +26,13 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
$timeout(function(){
element.addClass('ng-enter-active');
if(!self.didInitEvents) {
var onHardwareBackButton = function() {
self.hide();
};
self.scope.$on('$destroy', function() {
$ionicPlatform.offHardwareBackButton(onHardwareBackButton);
});
// Support Android back button to close
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
self.didInitEvents = true;
}
self.scope.$parent.$broadcast('modal.shown');
}, 20);
self._deregisterBackButton = $ionicPlatform.registerBackButtonAction(function(){
self.hide();
}, 200);
},
// Hide the modal
hide: function() {
@@ -65,6 +53,8 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
ionic.views.Modal.prototype.hide.call(this);
this.scope.$parent.$broadcast('modal.hidden');
this._deregisterBackButton && this._deregisterBackButton();
},
// Remove and destroy the modal scope