mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
InputType.Password enabled for prompt dialog
This commit is contained in:
13
BCL.csproj
13
BCL.csproj
@ -249,6 +249,7 @@
|
||||
<DependentUpon>dialogs.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\dialogs\index.ts" />
|
||||
<TypeScriptCompile Include="ui\dialogs\dialogs-common.ts" />
|
||||
<Content Include="_references.ts" />
|
||||
<Content Include="image-source\Readme.md" />
|
||||
<Content Include="http\Readme.md" />
|
||||
@ -362,15 +363,11 @@
|
||||
<UsingTask TaskName="BuildTasks.CopyForPlatformBuildTask" AssemblyFile="../../Build/lib/BuildTasks.dll" />
|
||||
<Target Name="AfterBuild">
|
||||
<CopyForPlatformBuildTask TargetPlatform="$(TargetOS)" IncludeTests="$(CopyTests)" Platforms="iOS;Android" InputFiles="@(GeneratedJavascript)" DestinationFolder="$(OutputPath)\$(Configuration)\" JSConfigFile="$(JSConfig)" AppMainJSFile="$(JSMainFile)" ProjectDir="$(ProjectDir)" />
|
||||
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='rd /q /s "../../Documentation/Docs/"' />
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='md "../../Documentation/Docs/"' />
|
||||
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='node ../../Documentation/Src/SnippetsExtractor/app.js -noclean -source bin\Documentation\Tests -destination ../../Documentation/Docs/' />
|
||||
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command="rd /q /s "../../Documentation/Docs/"" />
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command="md "../../Documentation/Docs/"" />
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command="node ../../Documentation/Src/SnippetsExtractor/app.js -noclean -source bin\Documentation\Tests -destination ../../Documentation/Docs/" />
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command="node ../../Documentation/Src/TypeScriptAPIExtractor/app.js @(TypeScriptCompile) $(IntermediateOutputPath)\api.xml" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="false" LogStandardErrorAsError="true" />
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command='"../../Documentation/Src/XMLAPIPrinting/bin/Release/XMLAPIPrinting.exe" $(IntermediateOutputPath)\api.xml "../../Documentation/Docs/"' />
|
||||
|
||||
<Exec Condition=" '$(Configuration)' == 'Documentation' " Command=""../../Documentation/Src/XMLAPIPrinting/bin/Release/XMLAPIPrinting.exe" $(IntermediateOutputPath)\api.xml "../../Documentation/Docs/"" />
|
||||
</Target>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
|
21
ui/dialogs/dialogs-common.ts
Normal file
21
ui/dialogs/dialogs-common.ts
Normal file
@ -0,0 +1,21 @@
|
||||
export var STRING = "string",
|
||||
PROMPT = "Prompt",
|
||||
CONFIRM = "Confirm",
|
||||
ALERT = "Alert",
|
||||
OK = "OK",
|
||||
CANCEL = "Cancel";
|
||||
|
||||
/**
|
||||
* Defines the input type for prompt dialog.
|
||||
*/
|
||||
export enum InputType {
|
||||
/**
|
||||
* Plain text input type.
|
||||
*/
|
||||
PlainText,
|
||||
|
||||
/**
|
||||
* Password input type.
|
||||
*/
|
||||
Password,
|
||||
}
|
@ -3,15 +3,13 @@
|
||||
*/
|
||||
import promises = require("promises");
|
||||
import dialogs = require("ui/dialogs");
|
||||
import dialogs_common = require("ui/dialogs/dialogs-common");
|
||||
import appmodule = require("application");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
var STRING = "string",
|
||||
PROMPT = "Prompt",
|
||||
CONFIRM = "Confirm",
|
||||
ALERT = "Alert",
|
||||
OK = "OK",
|
||||
CANCEL = "Cancel";
|
||||
// merge the exports of the request file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(dialogs_common, exports);
|
||||
|
||||
function createAlertDialog(message: string, options: dialogs.DialogOptions): android.app.AlertDialog.Builder {
|
||||
var alert = new android.app.AlertDialog.Builder(appmodule.android.foregroundActivity);
|
||||
@ -55,12 +53,12 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options
|
||||
}
|
||||
}
|
||||
|
||||
export function alert(message: string, options = { title: ALERT, okButtonText: OK }): promises.Promise<void> {
|
||||
export function alert(message: string, options = { title: dialogs_common.ALERT, okButtonText: dialogs_common.OK }): promises.Promise<void> {
|
||||
var d = promises.defer<void>();
|
||||
try {
|
||||
var alert = createAlertDialog(message, options);
|
||||
|
||||
alert.setPositiveButton(options.okButtonText, new android.content.DialogInterface.OnClickListener({
|
||||
alert.setPositiveButton(options.okButtonText, new android.content.DialogInterface.OnClickListener({
|
||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||
dialog.cancel();
|
||||
d.resolve();
|
||||
@ -76,7 +74,7 @@ export function alert(message: string, options = { title: ALERT, okButtonText: O
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
export function confirm(message: string, options = { title: CONFIRM, okButtonText: OK, cancelButtonText: CANCEL }): promises.Promise<boolean> {
|
||||
export function confirm(message: string, options = { title: dialogs_common.CONFIRM, okButtonText: dialogs_common.OK, cancelButtonText: dialogs_common.CANCEL }): promises.Promise<boolean> {
|
||||
var d = promises.defer<boolean>();
|
||||
try {
|
||||
var alert = createAlertDialog(message, options);
|
||||
@ -92,12 +90,18 @@ export function confirm(message: string, options = { title: CONFIRM, okButtonTex
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
export function prompt(message: string, defaultText?: string, options = { title: PROMPT, okButtonText: OK, cancelButtonText: CANCEL }): promises.Promise<dialogs.PromptResult> {
|
||||
export function prompt(message: string, defaultText?: string,
|
||||
options = { title: dialogs_common.PROMPT, okButtonText: dialogs_common.OK, cancelButtonText: dialogs_common.CANCEL, inputType: dialogs_common.InputType.PlainText }): promises.Promise<dialogs.PromptResult> {
|
||||
var d = promises.defer<dialogs.PromptResult>();
|
||||
try {
|
||||
var alert = createAlertDialog(message, options);
|
||||
|
||||
var input = new android.widget.EditText(appmodule.android.context);
|
||||
|
||||
if (options.inputType == dialogs_common.InputType.Password) {
|
||||
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
}
|
||||
|
||||
input.setText(defaultText ? defaultText : "");
|
||||
|
||||
alert.setView(input);
|
||||
|
17
ui/dialogs/dialogs.d.ts
vendored
17
ui/dialogs/dialogs.d.ts
vendored
@ -1,6 +1,9 @@
|
||||
declare module "ui/dialogs" {
|
||||
import promises = require("promises");
|
||||
import view = require("ui/core/view");
|
||||
import dialogs_common = require("ui/dialogs/dialogs-common");
|
||||
|
||||
export var InputType: dialogs_common.InputType;
|
||||
|
||||
/**
|
||||
* The alert() method displays an alert box with a specified message.
|
||||
@ -21,7 +24,7 @@
|
||||
* @param message The text to display in the dialog box.
|
||||
* @param options The options for the dialog box. Optional.
|
||||
*/
|
||||
function prompt(message: string, defaultText?: string, options?: DialogButtonsOptions): promises.Promise<string>;
|
||||
function prompt(message: string, defaultText?: string, options?: PromptOptions): promises.Promise<string>;
|
||||
|
||||
/**
|
||||
* Provides options for the dialog.
|
||||
@ -44,7 +47,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the confirm.
|
||||
* Provides options for the confirm dialog.
|
||||
*/
|
||||
interface DialogButtonsOptions extends AlertOptions {
|
||||
/**
|
||||
@ -58,6 +61,16 @@
|
||||
neutralButtonText?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the prompt dialog.
|
||||
*/
|
||||
interface PromptOptions extends DialogButtonsOptions {
|
||||
/**
|
||||
* Gets or sets the prompt input type (plain text or password).
|
||||
*/
|
||||
inputType?: dialogs_common.InputType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides result data from the prompt dialog.
|
||||
*/
|
||||
|
@ -3,15 +3,13 @@
|
||||
*/
|
||||
import promises = require("promises");
|
||||
import dialogs = require("ui/dialogs");
|
||||
import dialogs_common = require("ui/dialogs/dialogs-common");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
var UIALERTVIEWDELEGATE = "UIAlertViewDelegate",
|
||||
STRING = "string",
|
||||
PROMPT = "Prompt",
|
||||
CONFIRM = "Confirm",
|
||||
ALERT = "Alert",
|
||||
OK = "OK",
|
||||
CANCEL = "Cancel";
|
||||
// merge the exports of the request file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(dialogs_common, exports);
|
||||
|
||||
|
||||
function createUIAlertView(message: string, options: dialogs.DialogOptions): UIKit.UIAlertView {
|
||||
var alert = new UIKit.UIAlertView();
|
||||
@ -49,7 +47,7 @@ function addButtonsToAlertDialog(alert: UIKit.UIAlertView, options: dialogs.Dial
|
||||
}
|
||||
}
|
||||
|
||||
export function alert(message: string, options = { title: ALERT, okButtonText: OK }): promises.Promise<void> {
|
||||
export function alert(message: string, options = { title: dialogs_common.ALERT, okButtonText: dialogs_common.OK }): promises.Promise<void> {
|
||||
var d = promises.defer<void>();
|
||||
try {
|
||||
var alert = createUIAlertView(message, options);
|
||||
@ -75,7 +73,7 @@ export function alert(message: string, options = { title: ALERT, okButtonText: O
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
export function confirm(message: string, options = { title: CONFIRM, okButtonText: OK, cancelButtonText: CANCEL }): promises.Promise<boolean> {
|
||||
export function confirm(message: string, options = { title: dialogs_common.CONFIRM, okButtonText: dialogs_common.OK, cancelButtonText: dialogs_common.CANCEL }): promises.Promise<boolean> {
|
||||
var d = promises.defer<boolean>();
|
||||
try {
|
||||
var alert = createUIAlertView(message, options);
|
||||
@ -100,11 +98,17 @@ export function confirm(message: string, options = { title: CONFIRM, okButtonTe
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
export function prompt(message: string, defaultText?: string, options = { title: PROMPT, okButtonText: OK, cancelButtonText: CANCEL, defaultText: "" }): promises.Promise<dialogs.PromptResult> {
|
||||
export function prompt(message: string, defaultText?: string,
|
||||
options = { title: dialogs_common.PROMPT, okButtonText: dialogs_common.OK, cancelButtonText: dialogs_common.CANCEL, inputType: dialogs_common.InputType.PlainText }): promises.Promise<dialogs.PromptResult> {
|
||||
var d = promises.defer<dialogs.PromptResult>();
|
||||
try {
|
||||
var alert = createUIAlertView(message, options);
|
||||
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStylePlainTextInput;
|
||||
|
||||
if (options.inputType === dialogs_common.InputType.Password) {
|
||||
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStyleSecureTextInput;
|
||||
} else {
|
||||
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStylePlainTextInput;
|
||||
}
|
||||
|
||||
addButtonsToAlertDialog(alert, options);
|
||||
|
||||
|
Reference in New Issue
Block a user