MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / action

Function action

packages/core/ui/dialogs/index.ios.ts:262–323  ·  view source on GitHub ↗
(...args)

Source from the content-addressed store, hash-verified

260}
261
262export 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) {

Callers 8

lazyFunction · 0.50
lazyFunction · 0.50
trapDurationFunction · 0.50
waitUntilNavigatedToFunction · 0.50
waitUntilNavigatedFromFunction · 0.50
retryFunction · 0.50
waitUntilTabViewReadyFunction · 0.50

Calls 5

isStringFunction · 0.90
isDefinedFunction · 0.90
showUIAlertControllerFunction · 0.85
indexOfMethod · 0.80
resolveFunction · 0.50

Tested by 1

trapDurationFunction · 0.40