Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes cancel button error on Action Sheet #1576

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions js/angular/service/actionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
* - `{string}` `titleText` The title to show on the action sheet.
* - `{string=}` `cancelText` The text for a 'cancel' button on the action sheet.
* - `{string=}` `destructiveText` The text for a 'danger' on the action sheet.
* - `{function=}` `cancel` Called if the cancel button is pressed or the backdrop is tapped.
* - `{function=}` `cancel` Called if the cancel button is pressed, the backdrop is tapped or
* the hardware back button is pressed.
* - `{function=}` `buttonClicked` Called when one of the non-destructive buttons is clicked,
* with the index of the button that was clicked and the button object. Return true to close
* the action sheet, or false to keep it opened.
Expand All @@ -77,26 +78,17 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
show: function(opts) {
var scope = $rootScope.$new(true);

extend(scope, {
cancel: angular.noop,
buttonClicked: angular.noop,
destructiveButtonClicked: angular.noop,
buttons: []
}, opts);
angular.extend(scope, opts);

// Compile the template
var 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 hideSheet = function(didCancel) {
// removes the actionSheet from the screen
var hideSheet = function(h) {
sheetEl.removeClass('action-sheet-up');
if(didCancel) {
$timeout(function(){
opts.cancel();
}, 200);
}

$animate.removeClass(element, 'active', function() {
scope.$destroy();
Expand All @@ -107,31 +99,36 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
scope.$deregisterBackButton && scope.$deregisterBackButton();
};

// Support Android back button to close
// registerBackButtonAction returns a callback to deregister the action
scope.$deregisterBackButton = $ionicPlatform.registerBackButtonAction(
function(){
hideSheet();
scope.cancel(); //
},
PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET
);


// called when the user presses the cancel button
scope.cancel = function() {
hideSheet(true);
hideSheet();
$timeout(function(){
// after the animation is out, call the cancel callback
opts.cancel && opts.cancel();
},200)
};

scope.buttonClicked = function(index) {
// Check if the button click event returned true, which means
// we can close the action sheet
if((opts.buttonClicked && opts.buttonClicked(index, opts.buttons[index])) === true) {
hideSheet(false);
hideSheet();
}
};

scope.destructiveButtonClicked = function() {
// Check if the destructive button click event returned true, which means
// we can close the action sheet
if((opts.destructiveButtonClicked && opts.destructiveButtonClicked()) === true) {
hideSheet(false);
hideSheet();
}
};

Expand Down