mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat($ionicPopup): on android, make back button close popup
Fixes #1222
This commit is contained in:
9
js/angular/service/actionSheet.js
vendored
9
js/angular/service/actionSheet.js
vendored
@@ -107,9 +107,12 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
|
||||
};
|
||||
|
||||
// Support Android back button to close
|
||||
scope.$deregisterBackButton = $ionicPlatform.registerBackButtonAction(function(){
|
||||
hideSheet();
|
||||
}, 300);
|
||||
scope.$deregisterBackButton = $ionicPlatform.registerBackButtonAction(
|
||||
function(){
|
||||
hideSheet();
|
||||
},
|
||||
PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET
|
||||
);
|
||||
|
||||
scope.cancel = function() {
|
||||
hideSheet(true);
|
||||
|
||||
3
js/angular/service/platform.js
vendored
3
js/angular/service/platform.js
vendored
@@ -1,3 +1,6 @@
|
||||
var PLATFORM_BACK_BUTTON_PRIORITY_VIEW = 100;
|
||||
var PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET = 300;
|
||||
var PLATFORM_BACK_BUTTON_PRIORITY_POPUP = 500;
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name $ionicPlatform
|
||||
|
||||
14
js/angular/service/popup.js
vendored
14
js/angular/service/popup.js
vendored
@@ -98,16 +98,15 @@ var POPUP_TPL =
|
||||
*/
|
||||
IonicModule
|
||||
.factory('$ionicPopup', [
|
||||
'$animate',
|
||||
'$ionicTemplateLoader',
|
||||
'$ionicBackdrop',
|
||||
'$log',
|
||||
'$q',
|
||||
'$timeout',
|
||||
'$rootScope',
|
||||
'$document',
|
||||
'$compile',
|
||||
function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $rootScope, $document, $compile) {
|
||||
'$ionicPlatform',
|
||||
function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $document, $compile, $ionicPlatform) {
|
||||
//TODO allow this to be configured
|
||||
var config = {
|
||||
stackPushDelay: 50
|
||||
@@ -348,6 +347,10 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
|
||||
});
|
||||
}
|
||||
|
||||
function onHardwareBackButton(e) {
|
||||
popupStack[0] && popupStack[0].responseDeferred.resolve();
|
||||
}
|
||||
|
||||
function showPopup(options) {
|
||||
var popupPromise = $ionicPopup._createPopup(options);
|
||||
var previousPopup = popupStack[0];
|
||||
@@ -363,6 +366,10 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
|
||||
//Add popup-open & backdrop if this is first popup
|
||||
document.body.classList.add('popup-open');
|
||||
$ionicBackdrop.retain();
|
||||
$ionicPopup._backButtonActionDone = $ionicPlatform.registerBackButtonAction(
|
||||
onHardwareBackButton,
|
||||
PLATFORM_BACK_BUTTON_PRIORITY_POPUP
|
||||
);
|
||||
}
|
||||
popupStack.unshift(popup);
|
||||
popup.show();
|
||||
@@ -386,6 +393,7 @@ function($animate, $ionicTemplateLoader, $ionicBackdrop, $log, $q, $timeout, $ro
|
||||
//Remove popup-open & backdrop if this is last popup
|
||||
document.body.classList.remove('popup-open');
|
||||
$ionicBackdrop.release();
|
||||
($ionicPopup._backButtonActionDone || angular.noop)();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
5
js/angular/service/viewService.js
vendored
5
js/angular/service/viewService.js
vendored
@@ -79,7 +79,10 @@ function($rootScope, $state, $location, $document, $animate, $ionicPlatform, $io
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
$ionicPlatform.registerBackButtonAction(onHardwareBackButton, 100);
|
||||
$ionicPlatform.registerBackButtonAction(
|
||||
onHardwareBackButton,
|
||||
PLATFORM_BACK_BUTTON_PRIORITY_VIEW
|
||||
);
|
||||
|
||||
}])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user