Options
All
  • Public
  • Public/Protected
  • All
Menu

Module dialogs

dialogs module is used to show dialogs, which is usually used to show user key information, input information, and complete simple interaction.

This module provides multiple configuration modes, which can be displayed in the application dialog or floating window, confirm dialog, input box, radio button, and so on.

You can use const dialogs = require('dialogs'); to import dialogs module. Then you can use dialogs.showInputDialog("Title", "Text"); to call the module's method.

You can also directly import the function you want to use, such as const { showInputDialog } = require('dialogs'); showInputDialog("Title", "Text");

Index

Type aliases

Dialog

Dialog: android.app.Dialog & DialogExt

Dialog type, extends from Dialog to add some methods and properties. See DialogExt.

DialogType

DialogType: "overlay" | "app"

The type of the dialog.

  • overlay: can be shown on other applications, need floating window permission.
  • app: application-level dialog, can only be shown in the current activity, no extra permission required.

Functions

buildDialog

  • Create a dialog. You can customize dialog's title, content, progress, input, button, etc.

    Parameters

    Returns Promise<Dialog>

    Dialog object's Promise

    "nodejs";
    const { buildDialog} = require("dialogs");
    async function main() {
      const dialog = await buildDialog({
         title: "",
         content: "",
      }).on("positive", () => {
          console.log("positive");
      });
      dialog.show();
    }
    main();
    

showAlertDialog

  • Show a alert dialog. Alert dialog includes title, content and a confirm button.

    example
    "nodejs";
    const { showAlertDialog } = require('dialogs');
    async function alert() {
      await showAlertDialog("This is an alert dialog.");
      await showAlertDialog("Summary", { content: "Some description" });
    }
    alert();
    

    Parameters

    Returns Promise<void>

    The result of the dialog. You can use await to wait for the dialog to dismiss.

showConfirmDialog

  • showConfirmDialog(title: string, properties?: DialogProperties): Promise<boolean>
  • Show a confirm dialog, including a confirm button and a cancel button.

    example
    "nodejs";
    const dialogs = require('dialogs');
    async function confirm() {
      const sure = await dialogs.showConfirmDialog("Are you sure?");
      console.log(sure); // true or false
      console.log(await dialogs.showConfirmDialog("Are you sure?", { positive: "Yes", negative: "No" }));
    }
    confirm();
    

    Parameters

    Returns Promise<boolean>

    The result of the dialog. You can use await to get the result.

showDialog

showInputDialog

  • showInputDialog(title: string, prefill?: string, properties?: DialogProperties): Promise<string | null>
  • show a input dialog.

    example
    "nodejs";
    const dialogs = require('dialogs');
    async function inputDialog() {
      const name = await dialogs.showInputDialog("Input your name", "Tony");
      if (name != "") {
          console.log(`hello, ${mName}`);
      }
    }
    inputDialog();
    

    Parameters

    • title: string

      The title of the input dialog.

    • Optional prefill: string

      The default text of the input dialog.

    • Optional properties: DialogProperties

      The configuration properties of the dialog. See DialogProperties

    Returns Promise<string | null>

    The promise of the input result. If the user cancels the input, the result will be null.

showMultiChoiceDialog

  • showMultiChoiceDialog(title: string, items: string[], initialSelectedIndices?: number[], properties?: DialogProperties): Promise<number[] | null>
  • Show a multi-choice dialog. Multi-choice dialog includes a title and a multi-choice list, and the user clicks on the list items to confirm.

    Parameters

    • title: string

      The title of the multi-choice dialog.

    • items: string[]

      The options of the multi-choice dialog.

    • Optional initialSelectedIndices: number[]

      The default selected options. The form is an array of the index of items array.

    • Optional properties: DialogProperties

      The configuration properties of the dialog. See DialogProperties

    Returns Promise<number[] | null>

    The promise of the selected indices. If the user cancels the multi-choice, the result will be an empty array.

    "nodejs";
    const { showMultiChoiceDialog } = require('dialogs');
    async function multiChoice() {
        const indices = await showMultiChoiceDialog("Choose items", ["item1", "item2", "item3"]);
        console.log(`selected items: ${indices}`);
    }
    

showSelectDialog

  • showSelectDialog(title: string, items: string[], properties?: DialogProperties): Promise<number>
  • Show a select dialog.

    example
    "nodejs";
    const { showSelectDialog } = require('dialogs');
    async function select() {
      const i = await showSelectDialog("Select an item", ["item1", "item2", "item3"]);
      console.log(`selected item: ${i}`);
    }
    select();
    

    Parameters

    • title: string

      The title of the select dialog.

    • items: string[]

      The options of the select dialog.

    • Optional properties: DialogProperties

      The configuration properties of the dialog. See DialogProperties

    Returns Promise<number>

    The promise of the selected index. If the user cancels the select, the result will be -1.

showSingleChoiceDialog

  • showSingleChoiceDialog(title: string, items: string[], initialSelectedIndex?: number, properties?: DialogProperties): Promise<number>
  • Show a radio dialog.

    example
    "nodejs";
    const { showSingleChoiceDialog } = require('dialogs');
    async function singleChoice() {
      const i = await showSingleChoiceDialog("Choose an item", ["item1", "item2", "item3"]);
      console.log(`selected item: ${i}`);
    }
    singleChoice();
    

    Parameters

    • title: string

      The title of the radio dialog.

    • items: string[]

      The options of the radio dialog.

    • Optional initialSelectedIndex: number

      The default selected index of the items array.

    • Optional properties: DialogProperties

      The configuration properties of the dialog. See DialogProperties

    Returns Promise<number>

    The promise of the selected index. If the user cancels the radio, the result will be -1.