mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -1,259 +1,256 @@
|
||||
// Types.
|
||||
import { View } from "../core/view";
|
||||
import { Color } from "../../color";
|
||||
import { Page } from "../page";
|
||||
import { isIOS } from "../../platform";
|
||||
import { Frame as FrameDef } from "../frame";
|
||||
import { isObject, isString } from "../../utils/types";
|
||||
import { View } from '../core/view';
|
||||
import { Color } from '../../color';
|
||||
import { Page } from '../page';
|
||||
import { isIOS } from '../../platform';
|
||||
import { Frame } from '../frame';
|
||||
import { isObject, isString } from '../../utils/types';
|
||||
|
||||
export const STRING = "string";
|
||||
export const PROMPT = "Prompt";
|
||||
export const CONFIRM = "Confirm";
|
||||
export const ALERT = "Alert";
|
||||
export const LOGIN = "Login";
|
||||
export const OK = "OK";
|
||||
export const CANCEL = "Cancel";
|
||||
export namespace DialogStrings {
|
||||
export const STRING = 'string';
|
||||
export const PROMPT = 'Prompt';
|
||||
export const CONFIRM = 'Confirm';
|
||||
export const ALERT = 'Alert';
|
||||
export const LOGIN = 'Login';
|
||||
export const OK = 'OK';
|
||||
export const CANCEL = 'Cancel';
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the dialog.
|
||||
*/
|
||||
export interface CancelableOptions {
|
||||
/**
|
||||
* [Android only] Gets or sets if the dialog can be canceled by taping outside of the dialog.
|
||||
*/
|
||||
cancelable?: boolean;
|
||||
/**
|
||||
* [Android only] Gets or sets if the dialog can be canceled by taping outside of the dialog.
|
||||
*/
|
||||
cancelable?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the dialog.
|
||||
*/
|
||||
export interface ActionOptions extends CancelableOptions {
|
||||
/**
|
||||
* Gets or sets the dialog title.
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* Gets or sets the dialog title.
|
||||
*/
|
||||
title?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the dialog message.
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* Gets or sets the dialog message.
|
||||
*/
|
||||
message?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the Cancel button text.
|
||||
*/
|
||||
cancelButtonText?: string;
|
||||
/**
|
||||
* Gets or sets the Cancel button text.
|
||||
*/
|
||||
cancelButtonText?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the list of available actions.
|
||||
*/
|
||||
actions?: Array<string>;
|
||||
/**
|
||||
* Gets or sets the list of available actions.
|
||||
*/
|
||||
actions?: Array<string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the dialog.
|
||||
*/
|
||||
export interface DialogOptions extends CancelableOptions {
|
||||
/**
|
||||
* Gets or sets the dialog title.
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* Gets or sets the dialog title.
|
||||
*/
|
||||
title?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the dialog message.
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* Gets or sets the dialog message.
|
||||
*/
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the alert.
|
||||
*/
|
||||
export interface AlertOptions extends DialogOptions {
|
||||
/**
|
||||
* Gets or sets the OK button text.
|
||||
*/
|
||||
okButtonText?: string;
|
||||
/**
|
||||
* Gets or sets the OK button text.
|
||||
*/
|
||||
okButtonText?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the confirm dialog.
|
||||
*/
|
||||
export interface ConfirmOptions extends AlertOptions {
|
||||
/**
|
||||
* Gets or sets the Cancel button text.
|
||||
*/
|
||||
cancelButtonText?: string;
|
||||
/**
|
||||
* Gets or sets the Cancel button text.
|
||||
*/
|
||||
cancelButtonText?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the neutral button text.
|
||||
*/
|
||||
neutralButtonText?: string;
|
||||
/**
|
||||
* Gets or sets the neutral button text.
|
||||
*/
|
||||
neutralButtonText?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the prompt dialog.
|
||||
*/
|
||||
export interface PromptOptions extends ConfirmOptions {
|
||||
/**
|
||||
* Gets or sets the default text to display in the input box.
|
||||
*/
|
||||
defaultText?: string;
|
||||
/**
|
||||
* Gets or sets the default text to display in the input box.
|
||||
*/
|
||||
defaultText?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the prompt input type (plain text, password, or email).
|
||||
*/
|
||||
inputType?: string;
|
||||
/**
|
||||
* Gets or sets the prompt input type (plain text, password, or email).
|
||||
*/
|
||||
inputType?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the prompt capitalizationType (none, all, sentences, or words).
|
||||
*/
|
||||
capitalizationType?: string;
|
||||
/**
|
||||
* Gets or sets the prompt capitalizationType (none, all, sentences, or words).
|
||||
*/
|
||||
capitalizationType?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides result data from the prompt dialog.
|
||||
*/
|
||||
export interface PromptResult {
|
||||
/**
|
||||
* Gets or sets the prompt dialog boolean result.
|
||||
*/
|
||||
result: boolean;
|
||||
/**
|
||||
* Gets or sets the prompt dialog boolean result.
|
||||
*/
|
||||
result: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the text entered in the prompt dialog.
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Gets or sets the text entered in the prompt dialog.
|
||||
*/
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides result data from the login dialog.
|
||||
*/
|
||||
export interface LoginResult {
|
||||
/**
|
||||
* Gets or sets the login dialog boolean result.
|
||||
*/
|
||||
result: boolean;
|
||||
/**
|
||||
* Gets or sets the login dialog boolean result.
|
||||
*/
|
||||
result: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the user entered in the login dialog.
|
||||
*/
|
||||
userName: string;
|
||||
/**
|
||||
* Gets or sets the user entered in the login dialog.
|
||||
*/
|
||||
userName: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the password entered in the login dialog.
|
||||
*/
|
||||
password: string;
|
||||
/**
|
||||
* Gets or sets the password entered in the login dialog.
|
||||
*/
|
||||
password: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the login dialog.
|
||||
*/
|
||||
export interface LoginOptions extends ConfirmOptions {
|
||||
/**
|
||||
* Gets or sets the default text to display as hint in the user name input box.
|
||||
*/
|
||||
userNameHint?: string;
|
||||
/**
|
||||
* Gets or sets the default text to display as hint in the user name input box.
|
||||
*/
|
||||
userNameHint?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the default text to display as hint in the password input box.
|
||||
*/
|
||||
passwordHint?: string;
|
||||
/**
|
||||
* Gets or sets the default text to display as hint in the password input box.
|
||||
*/
|
||||
passwordHint?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the default text to display in the user name input box.
|
||||
*/
|
||||
userName?: string;
|
||||
/**
|
||||
* Gets or sets the default text to display in the user name input box.
|
||||
*/
|
||||
userName?: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the default text to display in the password input box.
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* Gets or sets the default text to display in the password input box.
|
||||
*/
|
||||
password?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the input type for prompt dialog.
|
||||
*/
|
||||
export module inputType {
|
||||
/**
|
||||
* Plain text input type.
|
||||
*/
|
||||
export const text: string = "text";
|
||||
/**
|
||||
* Plain text input type.
|
||||
*/
|
||||
export const text: string = 'text';
|
||||
|
||||
/**
|
||||
* Password input type.
|
||||
*/
|
||||
export const password: string = "password";
|
||||
/**
|
||||
* Password input type.
|
||||
*/
|
||||
export const password: string = 'password';
|
||||
|
||||
/**
|
||||
* Email input type.
|
||||
*/
|
||||
export const email: string = "email";
|
||||
/**
|
||||
* Email input type.
|
||||
*/
|
||||
export const email: string = 'email';
|
||||
|
||||
/**
|
||||
* Number input type
|
||||
*/
|
||||
export const number: string = "number";
|
||||
/**
|
||||
* Number input type
|
||||
*/
|
||||
export const number: string = 'number';
|
||||
|
||||
/**
|
||||
* Decimal input type
|
||||
*/
|
||||
export const decimal: string = "decimal";
|
||||
/**
|
||||
* Decimal input type
|
||||
*/
|
||||
export const decimal: string = 'decimal';
|
||||
|
||||
/**
|
||||
* Phone input type
|
||||
*/
|
||||
export const phone: string = "phone";
|
||||
/**
|
||||
* Phone input type
|
||||
*/
|
||||
export const phone: string = 'phone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the capitalization type for prompt dialog.
|
||||
*/
|
||||
export module capitalizationType {
|
||||
/**
|
||||
* No automatic capitalization.
|
||||
*/
|
||||
export const none: string = "none";
|
||||
/**
|
||||
* No automatic capitalization.
|
||||
*/
|
||||
export const none: string = 'none';
|
||||
|
||||
/**
|
||||
* Capitalizes every character.
|
||||
*/
|
||||
export const all: string = "all";
|
||||
/**
|
||||
* Capitalizes every character.
|
||||
*/
|
||||
export const all: string = 'all';
|
||||
|
||||
/**
|
||||
* Capitalize the first word of each sentence.
|
||||
*/
|
||||
export const sentences: string = "sentences";
|
||||
/**
|
||||
* Capitalize the first word of each sentence.
|
||||
*/
|
||||
export const sentences: string = 'sentences';
|
||||
|
||||
/**
|
||||
* Capitalize the first letter of every word.
|
||||
*/
|
||||
export const words: string = "words";
|
||||
/**
|
||||
* Capitalize the first letter of every word.
|
||||
*/
|
||||
export const words: string = 'words';
|
||||
}
|
||||
|
||||
let Frame: typeof FrameDef;
|
||||
export function getCurrentPage(): Page {
|
||||
if (!Frame) {
|
||||
Frame = require("../frame").Frame;
|
||||
}
|
||||
let topmostFrame = Frame.topmost();
|
||||
if (topmostFrame) {
|
||||
return topmostFrame.currentPage;
|
||||
}
|
||||
|
||||
let topmostFrame = Frame.topmost();
|
||||
if (topmostFrame) {
|
||||
return topmostFrame.currentPage;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function applySelectors<T extends View>(view: T, callback: (view: T) => void) {
|
||||
let currentPage = getCurrentPage();
|
||||
if (currentPage) {
|
||||
let styleScope = currentPage._styleScope;
|
||||
if (styleScope) {
|
||||
view._inheritStyleScope(styleScope);
|
||||
view.onLoaded();
|
||||
callback(view);
|
||||
view.onUnloaded();
|
||||
}
|
||||
}
|
||||
let currentPage = getCurrentPage();
|
||||
if (currentPage) {
|
||||
let styleScope = currentPage._styleScope;
|
||||
if (styleScope) {
|
||||
view._inheritStyleScope(styleScope);
|
||||
view.onLoaded();
|
||||
callback(view);
|
||||
view.onUnloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let button: View;
|
||||
@@ -261,93 +258,93 @@ let label: View;
|
||||
let textField: View;
|
||||
|
||||
export function getButtonColors(): { color: Color; backgroundColor: Color } {
|
||||
if (!button) {
|
||||
const Button = require("../button").Button;
|
||||
button = new Button();
|
||||
if (isIOS) {
|
||||
button._setupUI(<any>{});
|
||||
}
|
||||
}
|
||||
if (!button) {
|
||||
const Button = require('../button').Button;
|
||||
button = new Button();
|
||||
if (isIOS) {
|
||||
button._setupUI(<any>{});
|
||||
}
|
||||
}
|
||||
|
||||
let buttonColor: Color;
|
||||
let buttonBackgroundColor: Color;
|
||||
applySelectors(button, (btn) => {
|
||||
buttonColor = btn.color;
|
||||
buttonBackgroundColor = <Color>btn.backgroundColor;
|
||||
});
|
||||
let buttonColor: Color;
|
||||
let buttonBackgroundColor: Color;
|
||||
applySelectors(button, (btn) => {
|
||||
buttonColor = btn.color;
|
||||
buttonBackgroundColor = <Color>btn.backgroundColor;
|
||||
});
|
||||
|
||||
return { color: buttonColor, backgroundColor: buttonBackgroundColor };
|
||||
return { color: buttonColor, backgroundColor: buttonBackgroundColor };
|
||||
}
|
||||
|
||||
export function getLabelColor(): Color {
|
||||
if (!label) {
|
||||
const Label = require("../label").Label;
|
||||
label = new Label();
|
||||
if (isIOS) {
|
||||
label._setupUI(<any>{});
|
||||
}
|
||||
}
|
||||
if (!label) {
|
||||
const Label = require('../label').Label;
|
||||
label = new Label();
|
||||
if (isIOS) {
|
||||
label._setupUI(<any>{});
|
||||
}
|
||||
}
|
||||
|
||||
let labelColor: Color;
|
||||
applySelectors(label, (lbl) => {
|
||||
labelColor = lbl.color;
|
||||
});
|
||||
let labelColor: Color;
|
||||
applySelectors(label, (lbl) => {
|
||||
labelColor = lbl.color;
|
||||
});
|
||||
|
||||
return labelColor;
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
export function getTextFieldColor(): Color {
|
||||
if (!textField) {
|
||||
const TextField = require("../text-field").TextField;
|
||||
textField = new TextField();
|
||||
if (isIOS) {
|
||||
textField._setupUI(<any>{});
|
||||
}
|
||||
}
|
||||
if (!textField) {
|
||||
const TextField = require('../text-field').TextField;
|
||||
textField = new TextField();
|
||||
if (isIOS) {
|
||||
textField._setupUI(<any>{});
|
||||
}
|
||||
}
|
||||
|
||||
let textFieldColor: Color;
|
||||
applySelectors(textField, (tf) => {
|
||||
textFieldColor = tf.color;
|
||||
});
|
||||
let textFieldColor: Color;
|
||||
applySelectors(textField, (tf) => {
|
||||
textFieldColor = tf.color;
|
||||
});
|
||||
|
||||
return textFieldColor;
|
||||
return textFieldColor;
|
||||
}
|
||||
|
||||
export function isDialogOptions(arg): boolean {
|
||||
return arg && (arg.message || arg.title);
|
||||
return arg && (arg.message || arg.title);
|
||||
}
|
||||
|
||||
export function parseLoginOptions(args: any[]): LoginOptions {
|
||||
// Handle options object first
|
||||
if (args.length === 1 && isObject(args[0])) {
|
||||
return args[0];
|
||||
}
|
||||
// Handle options object first
|
||||
if (args.length === 1 && isObject(args[0])) {
|
||||
return args[0];
|
||||
}
|
||||
|
||||
let options: LoginOptions = {
|
||||
title: LOGIN,
|
||||
okButtonText: OK,
|
||||
cancelButtonText: CANCEL,
|
||||
};
|
||||
let options: LoginOptions = {
|
||||
title: DialogStrings.LOGIN,
|
||||
okButtonText: DialogStrings.OK,
|
||||
cancelButtonText: DialogStrings.CANCEL,
|
||||
};
|
||||
|
||||
if (isString(args[0])) {
|
||||
options.message = args[0];
|
||||
}
|
||||
if (isString(args[0])) {
|
||||
options.message = args[0];
|
||||
}
|
||||
|
||||
if (isString(args[1])) {
|
||||
options.userNameHint = args[1];
|
||||
}
|
||||
if (isString(args[1])) {
|
||||
options.userNameHint = args[1];
|
||||
}
|
||||
|
||||
if (isString(args[2])) {
|
||||
options.passwordHint = args[2];
|
||||
}
|
||||
if (isString(args[2])) {
|
||||
options.passwordHint = args[2];
|
||||
}
|
||||
|
||||
if (isString(args[3])) {
|
||||
options.userName = args[3];
|
||||
}
|
||||
if (isString(args[3])) {
|
||||
options.userName = args[3];
|
||||
}
|
||||
|
||||
if (isString(args[4])) {
|
||||
options.password = args[4];
|
||||
}
|
||||
if (isString(args[4])) {
|
||||
options.password = args[4];
|
||||
}
|
||||
|
||||
return options;
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -1,481 +1,384 @@
|
||||
/**
|
||||
* Android specific dialogs functions implementation.
|
||||
*/
|
||||
import {
|
||||
DialogOptions,
|
||||
ConfirmOptions,
|
||||
PromptOptions,
|
||||
PromptResult,
|
||||
LoginOptions,
|
||||
LoginResult,
|
||||
ActionOptions,
|
||||
} from "./dialogs-common";
|
||||
import {
|
||||
getLabelColor,
|
||||
getButtonColors,
|
||||
isDialogOptions,
|
||||
inputType,
|
||||
capitalizationType,
|
||||
ALERT,
|
||||
OK,
|
||||
CONFIRM,
|
||||
CANCEL,
|
||||
PROMPT,
|
||||
parseLoginOptions,
|
||||
} from "./dialogs-common";
|
||||
import { android as androidApp } from "../../application";
|
||||
import { DialogOptions, ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from './dialogs-common';
|
||||
import { getLabelColor, getButtonColors, isDialogOptions, inputType, capitalizationType, DialogStrings, parseLoginOptions } from './dialogs-common';
|
||||
import { android as androidApp } from '../../application';
|
||||
|
||||
export * from "./dialogs-common";
|
||||
export * from './dialogs-common';
|
||||
|
||||
function isString(value): value is string {
|
||||
return typeof value === "string";
|
||||
return typeof value === 'string';
|
||||
}
|
||||
|
||||
function createAlertDialog(
|
||||
options?: DialogOptions
|
||||
): android.app.AlertDialog.Builder {
|
||||
const alert = new android.app.AlertDialog.Builder(
|
||||
androidApp.foregroundActivity
|
||||
);
|
||||
alert.setTitle(options && isString(options.title) ? options.title : "");
|
||||
alert.setMessage(
|
||||
options && isString(options.message) ? options.message : ""
|
||||
);
|
||||
if (options && options.cancelable === false) {
|
||||
alert.setCancelable(false);
|
||||
}
|
||||
function createAlertDialog(options?: DialogOptions): android.app.AlertDialog.Builder {
|
||||
const alert = new android.app.AlertDialog.Builder(androidApp.foregroundActivity);
|
||||
alert.setTitle(options && isString(options.title) ? options.title : '');
|
||||
alert.setMessage(options && isString(options.message) ? options.message : '');
|
||||
if (options && options.cancelable === false) {
|
||||
alert.setCancelable(false);
|
||||
}
|
||||
|
||||
return alert;
|
||||
return alert;
|
||||
}
|
||||
|
||||
function showDialog(builder: android.app.AlertDialog.Builder) {
|
||||
const dlg = builder.show();
|
||||
const dlg = builder.show();
|
||||
|
||||
const labelColor = getLabelColor();
|
||||
if (labelColor) {
|
||||
const textViewId = dlg
|
||||
.getContext()
|
||||
.getResources()
|
||||
.getIdentifier("android:id/alertTitle", null, null);
|
||||
if (textViewId) {
|
||||
const tv = <android.widget.TextView>dlg.findViewById(textViewId);
|
||||
if (tv) {
|
||||
tv.setTextColor(labelColor.android);
|
||||
}
|
||||
}
|
||||
const labelColor = getLabelColor();
|
||||
if (labelColor) {
|
||||
const textViewId = dlg.getContext().getResources().getIdentifier('android:id/alertTitle', null, null);
|
||||
if (textViewId) {
|
||||
const tv = <android.widget.TextView>dlg.findViewById(textViewId);
|
||||
if (tv) {
|
||||
tv.setTextColor(labelColor.android);
|
||||
}
|
||||
}
|
||||
|
||||
const messageTextViewId = dlg
|
||||
.getContext()
|
||||
.getResources()
|
||||
.getIdentifier("android:id/message", null, null);
|
||||
if (messageTextViewId) {
|
||||
const messageTextView = <android.widget.TextView>(
|
||||
dlg.findViewById(messageTextViewId)
|
||||
);
|
||||
if (messageTextView) {
|
||||
messageTextView.setTextColor(labelColor.android);
|
||||
}
|
||||
}
|
||||
}
|
||||
const messageTextViewId = dlg.getContext().getResources().getIdentifier('android:id/message', null, null);
|
||||
if (messageTextViewId) {
|
||||
const messageTextView = <android.widget.TextView>dlg.findViewById(messageTextViewId);
|
||||
if (messageTextView) {
|
||||
messageTextView.setTextColor(labelColor.android);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let { color, backgroundColor } = getButtonColors();
|
||||
let { color, backgroundColor } = getButtonColors();
|
||||
|
||||
if (color) {
|
||||
let buttons: android.widget.Button[] = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let id = dlg
|
||||
.getContext()
|
||||
.getResources()
|
||||
.getIdentifier("android:id/button" + i, null, null);
|
||||
buttons[i] = <android.widget.Button>dlg.findViewById(id);
|
||||
}
|
||||
if (color) {
|
||||
let buttons: android.widget.Button[] = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let id = dlg
|
||||
.getContext()
|
||||
.getResources()
|
||||
.getIdentifier('android:id/button' + i, null, null);
|
||||
buttons[i] = <android.widget.Button>dlg.findViewById(id);
|
||||
}
|
||||
|
||||
buttons.forEach((button) => {
|
||||
if (button) {
|
||||
if (color) {
|
||||
button.setTextColor(color.android);
|
||||
}
|
||||
if (backgroundColor) {
|
||||
button.setBackgroundColor(backgroundColor.android);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
buttons.forEach((button) => {
|
||||
if (button) {
|
||||
if (color) {
|
||||
button.setTextColor(color.android);
|
||||
}
|
||||
if (backgroundColor) {
|
||||
button.setBackgroundColor(backgroundColor.android);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function addButtonsToAlertDialog(
|
||||
alert: android.app.AlertDialog.Builder,
|
||||
options: ConfirmOptions,
|
||||
callback: Function
|
||||
): void {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options: ConfirmOptions, callback: Function): void {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.okButtonText) {
|
||||
alert.setPositiveButton(
|
||||
options.okButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (
|
||||
dialog: android.content.DialogInterface,
|
||||
id: number
|
||||
) {
|
||||
dialog.cancel();
|
||||
callback(true);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
if (options.okButtonText) {
|
||||
alert.setPositiveButton(
|
||||
options.okButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||
dialog.cancel();
|
||||
callback(true);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (options.cancelButtonText) {
|
||||
alert.setNegativeButton(
|
||||
options.cancelButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (
|
||||
dialog: android.content.DialogInterface,
|
||||
id: number
|
||||
) {
|
||||
dialog.cancel();
|
||||
callback(false);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
if (options.cancelButtonText) {
|
||||
alert.setNegativeButton(
|
||||
options.cancelButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||
dialog.cancel();
|
||||
callback(false);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (options.neutralButtonText) {
|
||||
alert.setNeutralButton(
|
||||
options.neutralButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (
|
||||
dialog: android.content.DialogInterface,
|
||||
id: number
|
||||
) {
|
||||
dialog.cancel();
|
||||
callback(undefined);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
alert.setOnDismissListener(
|
||||
new android.content.DialogInterface.OnDismissListener({
|
||||
onDismiss: function () {
|
||||
callback(false);
|
||||
},
|
||||
})
|
||||
);
|
||||
if (options.neutralButtonText) {
|
||||
alert.setNeutralButton(
|
||||
options.neutralButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||
dialog.cancel();
|
||||
callback(undefined);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
alert.setOnDismissListener(
|
||||
new android.content.DialogInterface.OnDismissListener({
|
||||
onDismiss: function () {
|
||||
callback(false);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function alert(arg: any): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
const options = !isDialogOptions(arg)
|
||||
? { title: ALERT, okButtonText: OK, message: arg + "" }
|
||||
: arg;
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
const options = !isDialogOptions(arg) ? { title: DialogStrings.ALERT, okButtonText: DialogStrings.OK, message: arg + '' } : arg;
|
||||
|
||||
const alert = createAlertDialog(options);
|
||||
const alert = createAlertDialog(options);
|
||||
|
||||
alert.setPositiveButton(
|
||||
options.okButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (
|
||||
dialog: android.content.DialogInterface,
|
||||
id: number
|
||||
) {
|
||||
dialog.cancel();
|
||||
resolve();
|
||||
},
|
||||
})
|
||||
);
|
||||
alert.setOnDismissListener(
|
||||
new android.content.DialogInterface.OnDismissListener({
|
||||
onDismiss: function () {
|
||||
resolve();
|
||||
},
|
||||
})
|
||||
);
|
||||
alert.setPositiveButton(
|
||||
options.okButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||
dialog.cancel();
|
||||
resolve();
|
||||
},
|
||||
})
|
||||
);
|
||||
alert.setOnDismissListener(
|
||||
new android.content.DialogInterface.OnDismissListener({
|
||||
onDismiss: function () {
|
||||
resolve();
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function confirm(arg: any): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
try {
|
||||
const options = !isDialogOptions(arg)
|
||||
? {
|
||||
title: CONFIRM,
|
||||
okButtonText: OK,
|
||||
cancelButtonText: CANCEL,
|
||||
message: arg + "",
|
||||
}
|
||||
: arg;
|
||||
const alert = createAlertDialog(options);
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
try {
|
||||
const options = !isDialogOptions(arg)
|
||||
? {
|
||||
title: DialogStrings.CONFIRM,
|
||||
okButtonText: DialogStrings.OK,
|
||||
cancelButtonText: DialogStrings.CANCEL,
|
||||
message: arg + '',
|
||||
}
|
||||
: arg;
|
||||
const alert = createAlertDialog(options);
|
||||
|
||||
addButtonsToAlertDialog(alert, options, function (result) {
|
||||
resolve(result);
|
||||
});
|
||||
addButtonsToAlertDialog(alert, options, function (result) {
|
||||
resolve(result);
|
||||
});
|
||||
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function prompt(arg: any): Promise<PromptResult> {
|
||||
let options: PromptOptions;
|
||||
let options: PromptOptions;
|
||||
|
||||
const defaultOptions = {
|
||||
title: PROMPT,
|
||||
okButtonText: OK,
|
||||
cancelButtonText: CANCEL,
|
||||
inputType: inputType.text,
|
||||
};
|
||||
const defaultOptions = {
|
||||
title: DialogStrings.PROMPT,
|
||||
okButtonText: DialogStrings.OK,
|
||||
cancelButtonText: DialogStrings.CANCEL,
|
||||
inputType: inputType.text,
|
||||
};
|
||||
|
||||
if (arguments.length === 1) {
|
||||
if (isString(arg)) {
|
||||
options = defaultOptions;
|
||||
options.message = arg;
|
||||
} else {
|
||||
options = arg;
|
||||
}
|
||||
} else if (arguments.length === 2) {
|
||||
if (isString(arguments[0]) && isString(arguments[1])) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
options.defaultText = arguments[1];
|
||||
}
|
||||
}
|
||||
if (arguments.length === 1) {
|
||||
if (isString(arg)) {
|
||||
options = defaultOptions;
|
||||
options.message = arg;
|
||||
} else {
|
||||
options = arg;
|
||||
}
|
||||
} else if (arguments.length === 2) {
|
||||
if (isString(arguments[0]) && isString(arguments[1])) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
options.defaultText = arguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise<PromptResult>((resolve, reject) => {
|
||||
try {
|
||||
const alert = createAlertDialog(options);
|
||||
return new Promise<PromptResult>((resolve, reject) => {
|
||||
try {
|
||||
const alert = createAlertDialog(options);
|
||||
|
||||
const input = new android.widget.EditText(
|
||||
androidApp.foregroundActivity
|
||||
);
|
||||
const input = new android.widget.EditText(androidApp.foregroundActivity);
|
||||
|
||||
if (options) {
|
||||
if (options.inputType === inputType.password) {
|
||||
input.setInputType(
|
||||
android.text.InputType.TYPE_CLASS_TEXT |
|
||||
android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
);
|
||||
} else if (options.inputType === inputType.email) {
|
||||
input.setInputType(
|
||||
android.text.InputType.TYPE_CLASS_TEXT |
|
||||
android.text.InputType
|
||||
.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
||||
);
|
||||
} else if (options.inputType === inputType.number) {
|
||||
input.setInputType(
|
||||
android.text.InputType.TYPE_CLASS_NUMBER
|
||||
);
|
||||
} else if (options.inputType === inputType.decimal) {
|
||||
input.setInputType(
|
||||
android.text.InputType.TYPE_CLASS_NUMBER |
|
||||
android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
);
|
||||
} else if (options.inputType === inputType.phone) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
|
||||
}
|
||||
if (options) {
|
||||
if (options.inputType === inputType.password) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
} else if (options.inputType === inputType.email) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
||||
} else if (options.inputType === inputType.number) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
|
||||
} else if (options.inputType === inputType.decimal) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
} else if (options.inputType === inputType.phone) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
|
||||
}
|
||||
|
||||
switch (options.capitalizationType) {
|
||||
case capitalizationType.all: {
|
||||
input.setInputType(
|
||||
input.getInputType() |
|
||||
android.text.InputType
|
||||
.TYPE_TEXT_FLAG_CAP_CHARACTERS
|
||||
);
|
||||
break;
|
||||
}
|
||||
case capitalizationType.sentences: {
|
||||
input.setInputType(
|
||||
input.getInputType() |
|
||||
android.text.InputType
|
||||
.TYPE_TEXT_FLAG_CAP_SENTENCES
|
||||
);
|
||||
break;
|
||||
}
|
||||
case capitalizationType.words: {
|
||||
input.setInputType(
|
||||
input.getInputType() |
|
||||
android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (options.capitalizationType) {
|
||||
case capitalizationType.all: {
|
||||
input.setInputType(input.getInputType() | android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
|
||||
break;
|
||||
}
|
||||
case capitalizationType.sentences: {
|
||||
input.setInputType(input.getInputType() | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
||||
break;
|
||||
}
|
||||
case capitalizationType.words: {
|
||||
input.setInputType(input.getInputType() | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input.setText((options && options.defaultText) || "");
|
||||
input.setText((options && options.defaultText) || '');
|
||||
|
||||
alert.setView(input);
|
||||
alert.setView(input);
|
||||
|
||||
const getText = function () {
|
||||
return input.getText().toString();
|
||||
};
|
||||
const getText = function () {
|
||||
return input.getText().toString();
|
||||
};
|
||||
|
||||
addButtonsToAlertDialog(alert, options, function (r) {
|
||||
resolve({ result: r, text: getText() });
|
||||
});
|
||||
addButtonsToAlertDialog(alert, options, function (r) {
|
||||
resolve({ result: r, text: getText() });
|
||||
});
|
||||
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function login(...args: any[]): Promise<LoginResult> {
|
||||
let options: LoginOptions = parseLoginOptions(args);
|
||||
let options: LoginOptions = parseLoginOptions(args);
|
||||
|
||||
return new Promise<LoginResult>((resolve, reject) => {
|
||||
try {
|
||||
const context = androidApp.foregroundActivity;
|
||||
return new Promise<LoginResult>((resolve, reject) => {
|
||||
try {
|
||||
const context = androidApp.foregroundActivity;
|
||||
|
||||
const alert = createAlertDialog(options);
|
||||
const alert = createAlertDialog(options);
|
||||
|
||||
const userNameInput = new android.widget.EditText(context);
|
||||
const userNameInput = new android.widget.EditText(context);
|
||||
|
||||
userNameInput.setHint(
|
||||
options.userNameHint ? options.userNameHint : ""
|
||||
);
|
||||
userNameInput.setText(options.userName ? options.userName : "");
|
||||
userNameInput.setHint(options.userNameHint ? options.userNameHint : '');
|
||||
userNameInput.setText(options.userName ? options.userName : '');
|
||||
|
||||
const passwordInput = new android.widget.EditText(context);
|
||||
passwordInput.setInputType(
|
||||
android.text.InputType.TYPE_CLASS_TEXT |
|
||||
android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
);
|
||||
passwordInput.setTypeface(android.graphics.Typeface.DEFAULT);
|
||||
const passwordInput = new android.widget.EditText(context);
|
||||
passwordInput.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
passwordInput.setTypeface(android.graphics.Typeface.DEFAULT);
|
||||
|
||||
passwordInput.setHint(
|
||||
options.passwordHint ? options.passwordHint : ""
|
||||
);
|
||||
passwordInput.setText(options.password ? options.password : "");
|
||||
passwordInput.setHint(options.passwordHint ? options.passwordHint : '');
|
||||
passwordInput.setText(options.password ? options.password : '');
|
||||
|
||||
const layout = new android.widget.LinearLayout(context);
|
||||
layout.setOrientation(1);
|
||||
layout.addView(userNameInput);
|
||||
layout.addView(passwordInput);
|
||||
const layout = new android.widget.LinearLayout(context);
|
||||
layout.setOrientation(1);
|
||||
layout.addView(userNameInput);
|
||||
layout.addView(passwordInput);
|
||||
|
||||
alert.setView(layout);
|
||||
alert.setView(layout);
|
||||
|
||||
addButtonsToAlertDialog(alert, options, function (r) {
|
||||
resolve({
|
||||
result: r,
|
||||
userName: userNameInput.getText().toString(),
|
||||
password: passwordInput.getText().toString(),
|
||||
});
|
||||
});
|
||||
addButtonsToAlertDialog(alert, options, function (r) {
|
||||
resolve({
|
||||
result: r,
|
||||
userName: userNameInput.getText().toString(),
|
||||
password: passwordInput.getText().toString(),
|
||||
});
|
||||
});
|
||||
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function action(arg: any): Promise<string> {
|
||||
let options: ActionOptions;
|
||||
let options: ActionOptions;
|
||||
|
||||
const defaultOptions = { title: null, cancelButtonText: CANCEL };
|
||||
const defaultOptions = { title: null, cancelButtonText: DialogStrings.CANCEL };
|
||||
|
||||
if (arguments.length === 1) {
|
||||
if (isString(arguments[0])) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
} else {
|
||||
options = arguments[0];
|
||||
}
|
||||
} else if (arguments.length === 2) {
|
||||
if (isString(arguments[0]) && isString(arguments[1])) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
options.cancelButtonText = arguments[1];
|
||||
}
|
||||
} else if (arguments.length === 3) {
|
||||
if (
|
||||
isString(arguments[0]) &&
|
||||
isString(arguments[1]) &&
|
||||
typeof arguments[2] !== "undefined"
|
||||
) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
options.cancelButtonText = arguments[1];
|
||||
options.actions = arguments[2];
|
||||
}
|
||||
}
|
||||
if (arguments.length === 1) {
|
||||
if (isString(arguments[0])) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
} else {
|
||||
options = arguments[0];
|
||||
}
|
||||
} else if (arguments.length === 2) {
|
||||
if (isString(arguments[0]) && isString(arguments[1])) {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
options.cancelButtonText = arguments[1];
|
||||
}
|
||||
} else if (arguments.length === 3) {
|
||||
if (isString(arguments[0]) && isString(arguments[1]) && typeof arguments[2] !== 'undefined') {
|
||||
options = defaultOptions;
|
||||
options.message = arguments[0];
|
||||
options.cancelButtonText = arguments[1];
|
||||
options.actions = arguments[2];
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
try {
|
||||
const activity =
|
||||
androidApp.foregroundActivity || androidApp.startActivity;
|
||||
const alert = new android.app.AlertDialog.Builder(activity);
|
||||
const message =
|
||||
options && isString(options.message) ? options.message : "";
|
||||
const title =
|
||||
options && isString(options.title) ? options.title : "";
|
||||
if (options && options.cancelable === false) {
|
||||
alert.setCancelable(false);
|
||||
}
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
try {
|
||||
const activity = androidApp.foregroundActivity || androidApp.startActivity;
|
||||
const alert = new android.app.AlertDialog.Builder(activity);
|
||||
const message = options && isString(options.message) ? options.message : '';
|
||||
const title = options && isString(options.title) ? options.title : '';
|
||||
if (options && options.cancelable === false) {
|
||||
alert.setCancelable(false);
|
||||
}
|
||||
|
||||
if (title) {
|
||||
alert.setTitle(title);
|
||||
if (!options.actions) {
|
||||
alert.setMessage(message);
|
||||
}
|
||||
} else {
|
||||
alert.setTitle(message);
|
||||
}
|
||||
if (title) {
|
||||
alert.setTitle(title);
|
||||
if (!options.actions) {
|
||||
alert.setMessage(message);
|
||||
}
|
||||
} else {
|
||||
alert.setTitle(message);
|
||||
}
|
||||
|
||||
if (options.actions) {
|
||||
alert.setItems(
|
||||
options.actions,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (
|
||||
dialog: android.content.DialogInterface,
|
||||
which: number
|
||||
) {
|
||||
resolve(options.actions[which]);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
if (options.actions) {
|
||||
alert.setItems(
|
||||
options.actions,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, which: number) {
|
||||
resolve(options.actions[which]);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isString(options.cancelButtonText)) {
|
||||
alert.setNegativeButton(
|
||||
options.cancelButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (
|
||||
dialog: android.content.DialogInterface,
|
||||
id: number
|
||||
) {
|
||||
dialog.cancel();
|
||||
resolve(options.cancelButtonText);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
if (isString(options.cancelButtonText)) {
|
||||
alert.setNegativeButton(
|
||||
options.cancelButtonText,
|
||||
new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||
dialog.cancel();
|
||||
resolve(options.cancelButtonText);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
alert.setOnDismissListener(
|
||||
new android.content.DialogInterface.OnDismissListener({
|
||||
onDismiss: function () {
|
||||
if (isString(options.cancelButtonText)) {
|
||||
resolve(options.cancelButtonText);
|
||||
} else {
|
||||
resolve("");
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
alert.setOnDismissListener(
|
||||
new android.content.DialogInterface.OnDismissListener({
|
||||
onDismiss: function () {
|
||||
if (isString(options.cancelButtonText)) {
|
||||
resolve(options.cancelButtonText);
|
||||
} else {
|
||||
resolve('');
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
showDialog(alert);
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
116
nativescript-core/ui/dialogs/index.d.ts
vendored
116
nativescript-core/ui/dialogs/index.d.ts
vendored
@@ -1,70 +1,63 @@
|
||||
import {
|
||||
ConfirmOptions,
|
||||
PromptOptions,
|
||||
AlertOptions,
|
||||
PromptResult,
|
||||
LoginOptions,
|
||||
LoginResult,
|
||||
ActionOptions,
|
||||
} from "./dialogs-common";
|
||||
import { ConfirmOptions, PromptOptions, AlertOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from './dialogs-common';
|
||||
export * from './dialogs-common';
|
||||
/**
|
||||
* Defines the input type for prompt dialog.
|
||||
*/
|
||||
export module inputType {
|
||||
/**
|
||||
* Plain text input type.
|
||||
*/
|
||||
export const text: string;
|
||||
/**
|
||||
* Plain text input type.
|
||||
*/
|
||||
export const text: string;
|
||||
|
||||
/**
|
||||
* Password input type.
|
||||
*/
|
||||
export const password: string;
|
||||
/**
|
||||
* Password input type.
|
||||
*/
|
||||
export const password: string;
|
||||
|
||||
/**
|
||||
* Email input type.
|
||||
*/
|
||||
export const email: string;
|
||||
/**
|
||||
* Email input type.
|
||||
*/
|
||||
export const email: string;
|
||||
|
||||
/**
|
||||
* Number input type.
|
||||
*/
|
||||
export const number: string;
|
||||
/**
|
||||
* Number input type.
|
||||
*/
|
||||
export const number: string;
|
||||
|
||||
/**
|
||||
* Decimal input type.
|
||||
*/
|
||||
export const decimal: string;
|
||||
/**
|
||||
* Decimal input type.
|
||||
*/
|
||||
export const decimal: string;
|
||||
|
||||
/**
|
||||
* Phone input type.
|
||||
*/
|
||||
export const phone: string;
|
||||
/**
|
||||
* Phone input type.
|
||||
*/
|
||||
export const phone: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the capitalization type for prompt dialog.
|
||||
*/
|
||||
export module capitalizationType {
|
||||
/**
|
||||
* No automatic capitalization.
|
||||
*/
|
||||
export const none: string;
|
||||
/**
|
||||
* No automatic capitalization.
|
||||
*/
|
||||
export const none: string;
|
||||
|
||||
/**
|
||||
* Capitalizes every character.
|
||||
*/
|
||||
export const all: string;
|
||||
/**
|
||||
* Capitalizes every character.
|
||||
*/
|
||||
export const all: string;
|
||||
|
||||
/**
|
||||
* Capitalize the first word of each sentence.
|
||||
*/
|
||||
export const sentences: string;
|
||||
/**
|
||||
* Capitalize the first word of each sentence.
|
||||
*/
|
||||
export const sentences: string;
|
||||
|
||||
/**
|
||||
* Capitalize the first letter of every word.
|
||||
*/
|
||||
export const words: string;
|
||||
/**
|
||||
* Capitalize the first letter of every word.
|
||||
*/
|
||||
export const words: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,10 +89,7 @@ export function confirm(options: ConfirmOptions): Promise<boolean>;
|
||||
* @param message The text to display in the dialog box.
|
||||
* @param defaultText The default text to display in the input box. Optional.
|
||||
*/
|
||||
export function prompt(
|
||||
message: string,
|
||||
defaultText?: string
|
||||
): Promise<PromptResult>;
|
||||
export function prompt(message: string, defaultText?: string): Promise<PromptResult>;
|
||||
|
||||
/**
|
||||
* The prompt() method displays a dialog box that prompts the visitor for input.
|
||||
@@ -115,13 +105,7 @@ export function prompt(options: PromptOptions): Promise<PromptResult>;
|
||||
* @param userName The default text to display in the user name input box. Optional.
|
||||
* @param password The default text to display in the password input box. Optional.
|
||||
*/
|
||||
export function login(
|
||||
message: string,
|
||||
userNameHint?: string,
|
||||
passwordHint?: string,
|
||||
userName?: string,
|
||||
password?: string
|
||||
): Promise<LoginResult>;
|
||||
export function login(message: string, userNameHint?: string, passwordHint?: string, userName?: string, password?: string): Promise<LoginResult>;
|
||||
|
||||
/**
|
||||
* The login() method displays a login dialog box that prompts the visitor for user name and password.
|
||||
@@ -129,11 +113,7 @@ export function login(
|
||||
* @param userNameHint The default text to display as a hint in the username input. Optional.
|
||||
* @param passwordHint The default text to display as a hint in the password input. Optional.
|
||||
*/
|
||||
export function login(
|
||||
message: string,
|
||||
userNameHint?: string,
|
||||
passwordHint?: string
|
||||
): Promise<LoginResult>;
|
||||
export function login(message: string, userNameHint?: string, passwordHint?: string): Promise<LoginResult>;
|
||||
|
||||
/**
|
||||
* The login() method displays a login dialog box that prompts the visitor for user name and password.
|
||||
@@ -147,11 +127,7 @@ export function login(options: LoginOptions): Promise<LoginResult>;
|
||||
* @param cancelButtonText The text to display in the cancel button.
|
||||
* @param actions List of available actions.
|
||||
*/
|
||||
export function action(
|
||||
message: string,
|
||||
cancelButtonText: string,
|
||||
actions: Array<string>
|
||||
): Promise<string>;
|
||||
export function action(message: string, cancelButtonText: string, actions: Array<string>): Promise<string>;
|
||||
|
||||
/**
|
||||
* The action() method displays a action box that prompts the visitor to choose some action.
|
||||
|
||||
@@ -1,90 +1,54 @@
|
||||
/**
|
||||
* iOS specific dialogs functions implementation.
|
||||
*/
|
||||
import { ios as iosView } from "../core/view";
|
||||
import { Trace } from "../../trace";
|
||||
import {
|
||||
ConfirmOptions,
|
||||
PromptOptions,
|
||||
PromptResult,
|
||||
LoginOptions,
|
||||
LoginResult,
|
||||
ActionOptions,
|
||||
getCurrentPage,
|
||||
getLabelColor,
|
||||
getButtonColors,
|
||||
getTextFieldColor,
|
||||
isDialogOptions,
|
||||
inputType,
|
||||
capitalizationType,
|
||||
ALERT,
|
||||
OK,
|
||||
CONFIRM,
|
||||
CANCEL,
|
||||
PROMPT,
|
||||
parseLoginOptions,
|
||||
} from "./dialogs-common";
|
||||
import { isString, isDefined, isFunction } from "../../utils/types";
|
||||
import { getRootView, ios } from "../../application";
|
||||
import { ios as iosView } from '../core/view';
|
||||
import { Trace } from '../../trace';
|
||||
import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions, getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, capitalizationType, DialogStrings, parseLoginOptions } from './dialogs-common';
|
||||
import { isString, isDefined, isFunction } from '../../utils/types';
|
||||
import { getRootView, ios } from '../../application';
|
||||
|
||||
export * from "./dialogs-common";
|
||||
export * from './dialogs-common';
|
||||
|
||||
function addButtonsToAlertController(
|
||||
alertController: UIAlertController,
|
||||
options: ConfirmOptions,
|
||||
callback?: Function
|
||||
): void {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
function addButtonsToAlertController(alertController: UIAlertController, options: ConfirmOptions, callback?: Function): void {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isString(options.cancelButtonText)) {
|
||||
alertController.addAction(
|
||||
UIAlertAction.actionWithTitleStyleHandler(
|
||||
options.cancelButtonText,
|
||||
UIAlertActionStyle.Default,
|
||||
() => {
|
||||
raiseCallback(callback, false);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
if (isString(options.cancelButtonText)) {
|
||||
alertController.addAction(
|
||||
UIAlertAction.actionWithTitleStyleHandler(options.cancelButtonText, UIAlertActionStyle.Default, () => {
|
||||
raiseCallback(callback, false);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isString(options.neutralButtonText)) {
|
||||
alertController.addAction(
|
||||
UIAlertAction.actionWithTitleStyleHandler(
|
||||
options.neutralButtonText,
|
||||
UIAlertActionStyle.Default,
|
||||
() => {
|
||||
raiseCallback(callback, undefined);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
if (isString(options.neutralButtonText)) {
|
||||
alertController.addAction(
|
||||
UIAlertAction.actionWithTitleStyleHandler(options.neutralButtonText, UIAlertActionStyle.Default, () => {
|
||||
raiseCallback(callback, undefined);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isString(options.okButtonText)) {
|
||||
alertController.addAction(
|
||||
UIAlertAction.actionWithTitleStyleHandler(
|
||||
options.okButtonText,
|
||||
UIAlertActionStyle.Default,
|
||||
() => {
|
||||
raiseCallback(callback, true);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
if (isString(options.okButtonText)) {
|
||||
alertController.addAction(
|
||||
UIAlertAction.actionWithTitleStyleHandler(options.okButtonText, UIAlertActionStyle.Default, () => {
|
||||
raiseCallback(callback, true);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function raiseCallback(callback, result) {
|
||||
if (isFunction(callback)) {
|
||||
callback(result);
|
||||
}
|
||||
if (isFunction(callback)) {
|
||||
callback(result);
|
||||
}
|
||||
}
|
||||
export function alert(arg: any): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
try {
|
||||
let options = !isDialogOptions(arg)
|
||||
? { title: ALERT, okButtonText: OK, message: arg + "" }
|
||||
? { title: DialogStrings.ALERT, okButtonText: DialogStrings.OK, message: arg + "" }
|
||||
: arg;
|
||||
let alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(
|
||||
options.title,
|
||||
@@ -108,9 +72,9 @@ export function confirm(arg: any): Promise<boolean> {
|
||||
try {
|
||||
let options = !isDialogOptions(arg)
|
||||
? {
|
||||
title: CONFIRM,
|
||||
okButtonText: OK,
|
||||
cancelButtonText: CANCEL,
|
||||
title: DialogStrings.CONFIRM,
|
||||
okButtonText: DialogStrings.OK,
|
||||
cancelButtonText: DialogStrings.CANCEL,
|
||||
message: arg + "",
|
||||
}
|
||||
: arg;
|
||||
@@ -135,9 +99,9 @@ export function prompt(arg: any): Promise<PromptResult> {
|
||||
let options: PromptOptions;
|
||||
|
||||
let defaultOptions = {
|
||||
title: PROMPT,
|
||||
okButtonText: OK,
|
||||
cancelButtonText: CANCEL,
|
||||
title: DialogStrings.PROMPT,
|
||||
okButtonText: DialogStrings.OK,
|
||||
cancelButtonText: DialogStrings.CANCEL,
|
||||
inputType: inputType.text,
|
||||
};
|
||||
|
||||
@@ -337,7 +301,7 @@ function showUIAlertController(alertController: UIAlertController) {
|
||||
export function action(): Promise<string> {
|
||||
let options: ActionOptions;
|
||||
|
||||
let defaultOptions = { title: null, cancelButtonText: CANCEL };
|
||||
let defaultOptions = { title: null, cancelButtonText: DialogStrings.CANCEL };
|
||||
|
||||
if (arguments.length === 1) {
|
||||
if (isString(arguments[0])) {
|
||||
|
||||
Reference in New Issue
Block a user