Modals

The Modals API provides methods for triggering native modal windows for alerts, confirmations and input prompts.

Usage
Modals.beep(3); //Beep 3 times

...

Modals.alert({
    title: 'Wellcome',
    message: 'Hello world',
    buttonTitle: 'Hi'
})
    .then(() => console.log('Dialog dismissed'))
    .catch(e => console.log('Error ', e));

...

Modals.confirm({
    title: 'Register',
    message: 'Do you want to proceed to registration?',
    cancelButtonTitle: 'Cancel',
    okButtonTitle: 'Proceed'
})
    .then((resp) => {
        if(resp == 1){
            console.log('Wellcome ');
        }else{
            console.log('Registration canceled');
        }
    })
    .catch(e => console.log('Error ', e));

...

Modals.prompt({
    title: 'Hello',
    message: 'What\'s your name?',
    cancelButtonTitle: 'Cancel',
    okButtonTitle: 'Register',
    inputText: ''
})
    .then((resp) => {
        if(resp.buttonIndex == 1){
            console.log('Wellcome ',resp.input1);
        }else{
            console.log('Canceled');
        }
    })
    .catch(e => console.log('Error ', e));
window.Modals.confirm({
    title: "Register",
    message: "Do you want to proceed to registration?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Proceed",
})
    .then((resp) => {
        if (resp == 1) {
            console.log("Wellcome ");
        } else {
            console.log("Registration canceled");
        }
    })
    .catch((e) => console.log("Error ", e));

...

window.Modals.prompt({
    title: "Hello",
    message: "What's your name?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Register",
    inputText: "",
})
    .then((resp) => {
        if (resp.buttonIndex == 1) {
            console.log("Wellcome ", resp.input1);
        } else {
            console.log("Canceled");
        }
    })
    .catch((e) => console.log("Error ", e));

...

window.Modals.alert({
    title: "Wellcome",
    message: "Hello world",
    buttonTitle: "Hi",
})
    .then(() => console.log("Dialog dismissed"))
    .catch((e) => console.log("Error ", e));
window.Modals.alert({
    title: "Wellcome",
    message: "Hello world",
    buttonTitle: "Hi",
})
    .then(() => console.log("Dialog dismissed"))
    .catch((e) => console.log("Error ", e));

...

window.Modals.confirm({
    title: "Register",
    message: "Do you want to proceed to registration?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Proceed",
})
    .then((resp) => {
        if (resp == 1) {
            console.log("Wellcome ");
        } else {
            console.log("Registration canceled");
        }
    })
    .catch((e) => console.log("Error ", e));

...

window.Modals.prompt({
    title: "Hello",
    message: "What's your name?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Register",
    inputText: "",
})
    .then((resp) => {
        if (resp.buttonIndex == 1) {
            console.log("Wellcome ", resp.input1);
        } else {
            console.log("Canceled");
        }
    })
    .catch((e) => console.log("Error ", e));
(<any>window).Modals.alert({
    title: "Wellcome",
    message: "Hello world",
    buttonTitle: "Hi",
})
    .then(() => console.log("Dialog dismissed"))
    .catch((e) => console.log("Error ", e));

(<any>window).Modals.confirm({
    title: "Register",
    message: "Do you want to proceed to registration?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Proceed",
})
    .then((resp) => {
        if (resp == 1) {
            console.log("Wellcome ");
        } else {
            console.log("Registration canceled");
        }
    })
    .catch((e) => console.log("Error ", e));

(<any>window).Modals.prompt({
    title: "Hello",
    message: "What's your name?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Register",
    inputText: "",
})
    .then((resp) => {
        if (resp.buttonIndex == 1) {
            console.log("Wellcome ", resp.input1);
        } else {
            console.log("Canceled");
        }
    })
    .catch((e) => console.log("Error ", e));
window.Modals.alert({
    title: "Wellcome",
    message: "Hello world",
    buttonTitle: "Hi",
})
    .then(() => console.log("Dialog dismissed"))
    .catch((e) => console.log("Error ", e));

...

window.Modals.confirm({
    title: "Register",
    message: "Do you want to proceed to registration?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Proceed",
})
    .then((resp) => {
        if (resp == 1) {
            console.log("Wellcome ");
        } else {
            console.log("Registration canceled");
        }
    })
    .catch((e) => console.log("Error ", e));

...

window.Modals.prompt({
    title: "Hello",
    message: "What's your name?",
    cancelButtonTitle: "Cancel",
    okButtonTitle: "Register",
    inputText: "",
})
    .then((resp) => {
        if (resp.buttonIndex == 1) {
            console.log("Wellcome ", resp.input1);
        } else {
            console.log("Canceled");
        }
    })
    .catch((e) => console.log("Error ", e));

Classes


Modals

alert
alert(options: AlertOptions): Promise<void>

Show an alert modal.


PARAMETERS
options: AlertOptions

RETURN
return: Promise<void>
beep
beep(count: number): void

Causes the device to beep.


PARAMETERS
count: number The number of beeps(default = 1).
confirm
confirm(options: ConfirmOptions): Promise<number>

Show a confirmation modal.

Returns a promise that resolves the button index that was clicked, or 0 if the user has dismissed the dialog by clicking outside the dialog box. Note that the index use one-based indexing.


PARAMETERS
options: ConfirmOptions

RETURN
return: Promise<number>
prompt
prompt(options: PromptOptions): Promise<PromptResult>

Show a prompt modal.


PARAMETERS
options: PromptOptions

RETURN
return: Promise<PromptResult>

Interfaces Used

AlertOptions

interface AlertOptions {
    buttonTitle ?: string;
    message : string;
    title : string;
}

ConfirmOptions

interface ConfirmOptions {
    cancelButtonTitle ?: string;
    message : string;
    okButtonTitle ?: string;
    title : string;
}

PromptOptions

interface PromptOptions {
    cancelButtonTitle ?: string;
    inputText ?: string;
    message : string;
    okButtonTitle ?: string;
    title : string;
}

PromptResult

interface PromptResult {
    buttonIndex : number; //The index of the pressed button
    input1 : string; //The text entered in the prompt dialog box
}