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

Function action

packages/core/ui/dialogs/index.android.ts:297–382  ·  view source on GitHub ↗
(...args)

Source from the content-addressed store, hash-verified

295}
296
297export function action(...args): Promise<string> {
298 let options: ActionOptions;
299
300 const defaultOptions = { title: null, cancelButtonText: DialogStrings.CANCEL };
301
302 if (args.length === 1) {
303 if (isString(args[0])) {
304 options = defaultOptions;
305 options.message = args[0];
306 } else {
307 options = args[0];
308 }
309 } else if (args.length === 2) {
310 if (isString(args[0]) && isString(args[1])) {
311 options = defaultOptions;
312 options.message = args[0];
313 options.cancelButtonText = args[1];
314 }
315 } else if (args.length === 3) {
316 if (isString(args[0]) && isString(args[1]) && typeof args[2] !== 'undefined') {
317 options = defaultOptions;
318 options.message = args[0];
319 options.cancelButtonText = args[1];
320 options.actions = args[2];
321 }
322 }
323
324 return new Promise<string>((resolve, reject) => {
325 try {
326 const alert = new android.app.AlertDialog.Builder(androidUtils.getCurrentActivity(), options.theme ? options.theme : -1);
327 const message = options && isString(options.message) ? options.message : '';
328 const title = options && isString(options.title) ? options.title : '';
329 if (options && options.cancelable === false) {
330 alert.setCancelable(false);
331 }
332
333 if (title) {
334 alert.setTitle(title);
335 if (!options.actions) {
336 alert.setMessage(message);
337 }
338 } else {
339 alert.setTitle(message);
340 }
341
342 if (options.actions) {
343 alert.setItems(
344 options.actions,
345 new android.content.DialogInterface.OnClickListener({
346 onClick: function (dialog: android.content.DialogInterface, which: number) {
347 resolve(options.actions[which]);
348 },
349 }),
350 );
351 }
352
353 if (isString(options.cancelButtonText)) {
354 alert.setNegativeButton(

Callers

nothing calls this directly

Calls 5

showDialogFunction · 0.85
isStringFunction · 0.70
cancelMethod · 0.65
resolveFunction · 0.50
setItemsMethod · 0.45

Tested by

no test coverage detected