mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat($ionicActionSheet): add cancelOnStateChange option, default true
Closes #1318 BREAKING CHANGE: $ionicActionSheet's default behavior is now to cancel when the app's state changes. To disable this behavior, pass `cancelOnStateChange: false` into $ionicActionSheet.show().
This commit is contained in:
10
js/angular/service/actionSheet.js
vendored
10
js/angular/service/actionSheet.js
vendored
@@ -82,6 +82,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
|
||||
* the action sheet, or false to keep it opened.
|
||||
* - `{function=}` `destructiveButtonClicked` Called when the destructive button is clicked.
|
||||
* Return true to close the action sheet, or false to keep it opened.
|
||||
* - `{boolean=}` `cancelOnStateChange` Whether to cancel the actionSheet when navigating
|
||||
* to a new state. Default true.
|
||||
*
|
||||
* @returns {function} `hideSheet` A function which, when called, hides & cancels the action sheet.
|
||||
*/
|
||||
@@ -94,14 +96,20 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
|
||||
buttonClicked: angular.noop,
|
||||
$deregisterBackButton: angular.noop,
|
||||
buttons: [],
|
||||
cancelOnStateChange: true
|
||||
}, opts || {});
|
||||
|
||||
|
||||
// Compile the template
|
||||
var element = scope.element = $compile('<ion-action-sheet buttons="buttons"></ion-action-sheet>')(scope);
|
||||
|
||||
// Grab the sheet element for animation
|
||||
var sheetEl = jqLite(element[0].querySelector('.action-sheet-wrapper'));
|
||||
|
||||
var stateChangeListenDone = scope.cancelOnStateChange ?
|
||||
$rootScope.$on('$stateChangeSuccess', function() { scope.cancel(); }) :
|
||||
angular.noop;
|
||||
|
||||
// removes the actionSheet from the screen
|
||||
scope.removeSheet = function(done) {
|
||||
if (scope.removed) return;
|
||||
@@ -110,6 +118,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
|
||||
sheetEl.removeClass('action-sheet-up');
|
||||
$document[0].body.classList.remove('action-sheet-open');
|
||||
scope.$deregisterBackButton();
|
||||
stateChangeListenDone();
|
||||
scope.cancel.$scope = null; //see last line
|
||||
|
||||
$animate.removeClass(element, 'active', function() {
|
||||
scope.$destroy();
|
||||
|
||||
@@ -84,4 +84,20 @@ describe('Ionic ActionSheet Service', function() {
|
||||
expect(cancelSpy).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should cancelOnStateChange by default', inject(function($rootScope) {
|
||||
var scope = setup();
|
||||
spyOn(scope, 'cancel');
|
||||
$rootScope.$broadcast('$stateChangeSuccess');
|
||||
expect(scope.cancel).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not cancelOnStateChange with option as false', inject(function($rootScope) {
|
||||
var scope = setup({
|
||||
cancelOnStateChange: false
|
||||
});
|
||||
spyOn(scope, 'cancel');
|
||||
$rootScope.$broadcast('$stateChangeSuccess');
|
||||
expect(scope.cancel).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user