feat($ionicModal): add hardwareBackButtonClose as option, default true

Closes #1397
This commit is contained in:
Andrew Joslin
2014-06-04 13:45:21 -06:00
parent 74a4612210
commit 9ffca1e4eb
4 changed files with 36 additions and 8 deletions

View File

@@ -59,7 +59,8 @@ IonicModule
'$ionicPlatform',
'$ionicTemplateLoader',
'$q',
function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTemplateLoader, $q) {
'$log',
function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTemplateLoader, $q, $log) {
/**
* @ngdoc controller
@@ -88,6 +89,8 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
* the modal when shown. Default: false.
* - `{boolean=}` `backdropClickToClose` Whether to close the modal on clicking the backdrop.
* Default: true.
* - `{boolean=}` `hardwareBackButtonClose` Whether the modal can be closed using the hardware
* back button on Android and similar devices. Default: true.
*/
initialize: function(opts) {
ionic.views.Modal.prototype.initialize.call(this, opts);
@@ -104,12 +107,10 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
var self = this;
if(self.scope.$$destroyed) {
console.error('Cannot call modal.show() after remove(). Please create a new modal instance using $ionicModal.');
$log.error('Cannot call modal.show() after remove(). Please create a new modal instance using $ionicModal.');
return;
}
console.log(self.scope);
var modalEl = jqLite(self.modalEl);
self.el.classList.remove('hide');
@@ -127,9 +128,13 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
.removeClass('ng-leave ng-leave-active');
self._isShown = true;
self._deregisterBackButton = $ionicPlatform.registerBackButtonAction(function(){
self.hide();
}, 200);
self._deregisterBackButton = self.hardwareBackButtonClose ?
$ionicPlatform.registerBackButtonAction(
angular.bind(self, self.hide),
PLATFORM_BACK_BUTTON_PRIORITY_MODAL
) :
angular.noop;
self._isOpenPromise = $q.defer();
ionic.views.Modal.prototype.show.call(self);

View File

@@ -1,5 +1,6 @@
var PLATFORM_BACK_BUTTON_PRIORITY_VIEW = 100;
var PLATFORM_BACK_BUTTON_PRIORITY_SIDE_MENU = 150;
var PLATFORM_BACK_BUTTON_PRIORITY_MODAL = 200;
var PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET = 300;
var PLATFORM_BACK_BUTTON_PRIORITY_POPUP = 400;
var PLATFORM_BACK_BUTTON_PRIORITY_LOADING = 500;