@@ -67,7 +67,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
67
67
* - `{string}` `titleText` The title to show on the action sheet.
68
68
* - `{string=}` `cancelText` The text for a 'cancel' button on the action sheet.
69
69
* - `{string=}` `destructiveText` The text for a 'danger' on the action sheet.
70
- * - `{function=}` `cancel` Called if the cancel button is pressed or the backdrop is tapped.
70
+ * - `{function=}` `cancel` Called if the cancel button is pressed, the backdrop is tapped or
71
+ * the hardware back button is pressed.
71
72
* - `{function=}` `buttonClicked` Called when one of the non-destructive buttons is clicked,
72
73
* with the index of the button that was clicked and the button object. Return true to close
73
74
* the action sheet, or false to keep it opened.
@@ -77,26 +78,17 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
77
78
show : function ( opts ) {
78
79
var scope = $rootScope . $new ( true ) ;
79
80
80
- extend ( scope , {
81
- cancel : angular . noop ,
82
- buttonClicked : angular . noop ,
83
- destructiveButtonClicked : angular . noop ,
84
- buttons : [ ]
85
- } , opts ) ;
81
+ angular . extend ( scope , opts ) ;
86
82
87
83
// Compile the template
88
84
var element = $compile ( '<ion-action-sheet buttons="buttons"></ion-action-sheet>' ) ( scope ) ;
89
85
90
86
// Grab the sheet element for animation
91
87
var sheetEl = jqLite ( element [ 0 ] . querySelector ( '.action-sheet-wrapper' ) ) ;
92
88
93
- var hideSheet = function ( didCancel ) {
89
+ // removes the actionSheet from the screen
90
+ var hideSheet = function ( h ) {
94
91
sheetEl . removeClass ( 'action-sheet-up' ) ;
95
- if ( didCancel ) {
96
- $timeout ( function ( ) {
97
- opts . cancel ( ) ;
98
- } , 200 ) ;
99
- }
100
92
101
93
$animate . removeClass ( element , 'active' , function ( ) {
102
94
scope . $destroy ( ) ;
@@ -107,31 +99,36 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
107
99
scope . $deregisterBackButton && scope . $deregisterBackButton ( ) ;
108
100
} ;
109
101
110
- // Support Android back button to close
102
+ // registerBackButtonAction returns a callback to deregister the action
111
103
scope . $deregisterBackButton = $ionicPlatform . registerBackButtonAction (
112
104
function ( ) {
113
- hideSheet ( ) ;
105
+ scope . cancel ( ) ; //
114
106
} ,
115
107
PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET
116
108
) ;
117
-
109
+
110
+ // called when the user presses the cancel button
118
111
scope . cancel = function ( ) {
119
- hideSheet ( true ) ;
112
+ hideSheet ( ) ;
113
+ $timeout ( function ( ) {
114
+ // after the animation is out, call the cancel callback
115
+ opts . cancel && opts . cancel ( ) ;
116
+ } , 200 )
120
117
} ;
121
118
122
119
scope . buttonClicked = function ( index ) {
123
120
// Check if the button click event returned true, which means
124
121
// we can close the action sheet
125
122
if ( ( opts . buttonClicked && opts . buttonClicked ( index , opts . buttons [ index ] ) ) === true ) {
126
- hideSheet ( false ) ;
123
+ hideSheet ( ) ;
127
124
}
128
125
} ;
129
126
130
127
scope . destructiveButtonClicked = function ( ) {
131
128
// Check if the destructive button click event returned true, which means
132
129
// we can close the action sheet
133
130
if ( ( opts . destructiveButtonClicked && opts . destructiveButtonClicked ( ) ) === true ) {
134
- hideSheet ( false ) ;
131
+ hideSheet ( ) ;
135
132
}
136
133
} ;
137
134
0 commit comments