| 260 | } |
| 261 | |
| 262 | export function action(...args): Promise<string> { |
| 263 | let options: ActionOptions; |
| 264 | |
| 265 | const defaultOptions = { title: null, cancelButtonText: DialogStrings.CANCEL }; |
| 266 | |
| 267 | if (args.length === 1) { |
| 268 | if (isString(args[0])) { |
| 269 | options = defaultOptions; |
| 270 | options.message = args[0]; |
| 271 | } else { |
| 272 | options = args[0]; |
| 273 | } |
| 274 | } else if (args.length === 2) { |
| 275 | if (isString(args[0]) && isString(args[1])) { |
| 276 | options = defaultOptions; |
| 277 | options.message = args[0]; |
| 278 | options.cancelButtonText = args[1]; |
| 279 | } |
| 280 | } else if (args.length === 3) { |
| 281 | if (isString(args[0]) && isString(args[1]) && isDefined(args[2])) { |
| 282 | options = defaultOptions; |
| 283 | options.message = args[0]; |
| 284 | options.cancelButtonText = args[1]; |
| 285 | options.actions = args[2]; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | return new Promise<string>((resolve, reject) => { |
| 290 | try { |
| 291 | let i: number; |
| 292 | let action: string; |
| 293 | const alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.ActionSheet); |
| 294 | |
| 295 | if (options.actions) { |
| 296 | for (i = 0; i < options.actions.length; i++) { |
| 297 | action = options.actions[i]; |
| 298 | if (isString(action)) { |
| 299 | const thisActionIsDestructive = options.destructiveActionsIndexes && options.destructiveActionsIndexes.indexOf(i) !== -1; |
| 300 | const dialogType = thisActionIsDestructive ? UIAlertActionStyle.Destructive : UIAlertActionStyle.Default; |
| 301 | alertController.addAction( |
| 302 | UIAlertAction.actionWithTitleStyleHandler(action, dialogType, (arg: UIAlertAction) => { |
| 303 | resolve(arg.title); |
| 304 | }), |
| 305 | ); |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | if (isString(options.cancelButtonText)) { |
| 311 | alertController.addAction( |
| 312 | UIAlertAction.actionWithTitleStyleHandler(options.cancelButtonText, UIAlertActionStyle.Cancel, (arg: UIAlertAction) => { |
| 313 | resolve(arg.title); |
| 314 | }), |
| 315 | ); |
| 316 | } |
| 317 | |
| 318 | showUIAlertController(alertController); |
| 319 | } catch (ex) { |