Android back button fixes, closes #454

This commit is contained in:
Adam Bradley
2014-01-30 22:01:20 -06:00
parent b20ce800ab
commit c3544d8a4a
5 changed files with 46 additions and 13 deletions

View File

@@ -1,4 +1,9 @@
## 0.9.23-alpha (pre-release)
- Android back button correctly goes back a view or closes the app
- CustomEvent polyfill improvements for Android
## 0.9.22 "Alpha Narwhal" (2014-01-30)
- Tap polyfill overhaul to remove 300ms delay when firing a click
- Android click firing twice fixes

View File

@@ -469,8 +469,7 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
};
}]);
;
(function() {
'use strict';
(function(ionic) {'use strict';
angular.module('ionic.service.platform', [])
@@ -495,7 +494,7 @@ angular.module('ionic.service.platform', [])
* @param {function} cb the callback to trigger when this event occurs
*/
onHardwareBackButton: function(cb) {
this.ready(function() {
ionic.Platform.ready(function() {
document.addEventListener('backbutton', cb, false);
});
},
@@ -506,7 +505,7 @@ angular.module('ionic.service.platform', [])
* @param {function} fn the listener function that was originally bound.
*/
offHardwareBackButton: function(fn) {
this.ready(function() {
ionic.Platform.ready(function() {
document.removeEventListener('backbutton', fn);
});
},
@@ -625,8 +624,8 @@ angular.module('ionic.service.templateLoad', [])
angular.module('ionic.service.view', ['ui.router'])
.run( ['$rootScope', '$state', '$location', '$document', '$animate',
function( $rootScope, $state, $location, $document, $animate) {
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',
function( $rootScope, $state, $location, $document, $animate, $ionicPlatform) {
// init the variables that keep track of the view history
$rootScope.$viewHistory = {
@@ -673,6 +672,21 @@ angular.module('ionic.service.view', ['ui.router'])
}
});
// Triggered when devices with a hardware back button (Android) is clicked by the user
// This is a Cordova/Phonegap platform specifc method
function onHardwareBackButton(e) {
if($rootScope.$viewHistory.backView) {
// there is a back view, go to it
$rootScope.$viewHistory.backView.go();
} else {
// there is no back view, so close the app instead
navigator.app.exitApp();
}
e.preventDefault();
return false;
}
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
}])
.factory('$ionicViewService', ['$rootScope', '$state', '$location', '$window', '$injector',

View File

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,4 @@
(function() {
'use strict';
(function(ionic) {'use strict';
angular.module('ionic.service.platform', [])
@@ -24,7 +23,7 @@ angular.module('ionic.service.platform', [])
* @param {function} cb the callback to trigger when this event occurs
*/
onHardwareBackButton: function(cb) {
this.ready(function() {
ionic.Platform.ready(function() {
document.addEventListener('backbutton', cb, false);
});
},
@@ -35,7 +34,7 @@ angular.module('ionic.service.platform', [])
* @param {function} fn the listener function that was originally bound.
*/
offHardwareBackButton: function(fn) {
this.ready(function() {
ionic.Platform.ready(function() {
document.removeEventListener('backbutton', fn);
});
},

View File

@@ -1,8 +1,8 @@
angular.module('ionic.service.view', ['ui.router'])
.run( ['$rootScope', '$state', '$location', '$document', '$animate',
function( $rootScope, $state, $location, $document, $animate) {
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',
function( $rootScope, $state, $location, $document, $animate, $ionicPlatform) {
// init the variables that keep track of the view history
$rootScope.$viewHistory = {
@@ -49,6 +49,21 @@ angular.module('ionic.service.view', ['ui.router'])
}
});
// Triggered when devices with a hardware back button (Android) is clicked by the user
// This is a Cordova/Phonegap platform specifc method
function onHardwareBackButton(e) {
if($rootScope.$viewHistory.backView) {
// there is a back view, go to it
$rootScope.$viewHistory.backView.go();
} else {
// there is no back view, so close the app instead
navigator.app.exitApp();
}
e.preventDefault();
return false;
}
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
}])
.factory('$ionicViewService', ['$rootScope', '$state', '$location', '$window', '$injector',