FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: implement capitalization type option for prompt dialogs (#6325) · NativeScript/NativeScript@ae6a661 · GitHub

Commit ae6a661

Browse files
authored andcommitted
feat: implement capitalization type option for prompt dialogs (#6325)
* feat: implement capitalization type option for prompt dialogs Allow setting auto capitalization to "none", "all", "sentences" and "words". This feature works on both Android and iOS. * feat: add capitalization type examples to test page for dialogs
1 parent 1232d1e commit ae6a661

6 files changed

Lines changed: 169 additions & 2 deletions

File tree

‎apps/app/ui-tests-app/dialogs/dialogs.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
<Button text="promptText" tap="{{ promptText }}" />
99
<Button text="promptPass" tap="{{ promptPass }}" />
1010
<Button text="promptEmail" tap="{{ promptEmail }}" />
11+
<Button text="promptCapitalizationNone" tap="{{ promptCapitalizationNone }}" />
12+
<Button text="promptCapitalizationAll" tap="{{ promptCapitalizationAll }}" />
13+
<Button text="promptCapitalizationSentences" tap="{{ promptCapitalizationSentences }}" />
14+
<Button text="promptCapitalizationWords" tap="{{ promptCapitalizationWords }}" />
1115
</StackLayout>
1216
</Page>

‎apps/app/ui-tests-app/dialogs/view-model.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,81 @@ export class SettingsViewModel extends observable.Observable {
137137
}
138138
});
139139
}
140+
141+
public promptCapitalizationNone(args: observable.EventData) {
142+
dialogs.prompt({
143+
title: "Name",
144+
message: "Enter name:",
145+
cancelButtonText: "Cancel",
146+
okButtonText: "OK",
147+
inputType: dialogs.inputType.text,
148+
capitalizationType: dialogs.capitalizationType.none
149+
}).then((promptResult) => {
150+
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
151+
if (promptResult.result) {
152+
this.set("name", promptResult.text);
153+
}
154+
else {
155+
this.set("name", "Harold Finch");
156+
}
157+
});
158+
}
159+
160+
public promptCapitalizationAll(args: observable.EventData) {
161+
dialogs.prompt({
162+
title: "Name",
163+
message: "Enter name:",
164+
cancelButtonText: "Cancel",
165+
okButtonText: "OK",
166+
inputType: dialogs.inputType.text,
167+
capitalizationType: dialogs.capitalizationType.all
168+
}).then((promptResult) => {
169+
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
170+
if (promptResult.result) {
171+
this.set("name", promptResult.text);
172+
}
173+
else {
174+
this.set("name", "Harold Finch");
175+
}
176+
});
177+
}
178+
179+
public promptCapitalizationSentences(args: observable.EventData) {
180+
dialogs.prompt({
181+
title: "Name",
182+
message: "Enter name:",
183+
cancelButtonText: "Cancel",
184+
okButtonText: "OK",
185+
inputType: dialogs.inputType.text,
186+
capitalizationType: dialogs.capitalizationType.sentences
187+
}).then((promptResult) => {
188+
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
189+
if (promptResult.result) {
190+
this.set("name", promptResult.text);
191+
}
192+
else {
193+
this.set("name", "Harold Finch");
194+
}
195+
});
196+
}
197+
198+
public promptCapitalizationWords(args: observable.EventData) {
199+
dialogs.prompt({
200+
title: "Name",
201+
message: "Enter name:",
202+
cancelButtonText: "Cancel",
203+
okButtonText: "OK",
204+
inputType: dialogs.inputType.text,
205+
capitalizationType: dialogs.capitalizationType.words
206+
}).then((promptResult) => {
207+
console.log("### Result: " + promptResult.result + ", Text: " + promptResult.text);
208+
if (promptResult.result) {
209+
this.set("name", promptResult.text);
210+
}
211+
else {
212+
this.set("name", "Harold Finch");
213+
}
214+
});
215+
}
140216
}
141217
export var settingsViewModel = new SettingsViewModel();

‎tns-core-modules/ui/dialogs/dialogs-common.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ export module inputType {
3333
export const email: string = "email";
3434
}
3535

36+
/**
37+
* Defines the capitalization type for prompt dialog.
38+
*/
39+
export module capitalizationType {
40+
/**
41+
* No automatic capitalization.
42+
*/
43+
export const none: string = "none";
44+
45+
/**
46+
* Capitalizes every character.
47+
*/
48+
export const all: string = "all";
49+
50+
/**
51+
* Capitalize the first word of each sentence.
52+
*/
53+
export const sentences: string = "sentences";
54+
55+
/**
56+
* Capitalize the first letter of every word.
57+
*/
58+
export const words: string = "words";
59+
}
60+
3661
let frame: typeof frameModule;
3762
export function getCurrentPage(): Page {
3863
if (!frame) {

‎tns-core-modules/ui/dialogs/dialogs.android.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Android specific dialogs functions implementation.
33
*/
44
import { DialogOptions, ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from ".";
5-
import { getLabelColor, getButtonColors, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common";
5+
import { getLabelColor, getButtonColors, isDialogOptions, inputType, capitalizationType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common";
66
import { android as androidApp } from "../../application";
77

88
export * from "./dialogs-common";
@@ -185,6 +185,21 @@ export function prompt(arg: any): Promise<PromptResult> {
185185
} else if (options.inputType === inputType.email) {
186186
input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
187187
}
188+
189+
switch (options.capitalizationType) {
190+
case capitalizationType.all: {
191+
input.setInputType(input.getInputType() | android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
192+
break;
193+
}
194+
case capitalizationType.sentences: {
195+
input.setInputType(input.getInputType() | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
196+
break;
197+
}
198+
case capitalizationType.words: {
199+
input.setInputType(input.getInputType() | android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS);
200+
break;
201+
}
202+
}
188203
}
189204

190205
input.setText(options && options.defaultText || "");

‎tns-core-modules/ui/dialogs/dialogs.d.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ export module inputType {
2323
export var email: string;
2424
}
2525

26+
/**
27+
* Defines the capitalization type for prompt dialog.
28+
*/
29+
export module capitalizationType {
30+
/**
31+
* No automatic capitalization.
32+
*/
33+
export var none: string;
34+
35+
/**
36+
* Capitalizes every character.
37+
*/
38+
export var all: string;
39+
40+
/**
41+
* Capitalize the first word of each sentence.
42+
*/
43+
export var sentences: string;
44+
45+
/**
46+
* Capitalize the first letter of every word.
47+
*/
48+
export var words: string;
49+
}
50+
2651
/**
2752
* The alert() method displays an alert box with a specified message.
2853
* @param message Specifies the text to display in the alert box.
@@ -177,6 +202,11 @@ export interface PromptOptions extends ConfirmOptions {
177202
* Gets or sets the prompt input type (plain text, password, or email).
178203
*/
179204
inputType?: string;
205+
206+
/**
207+
* Gets or sets the prompt capitalizationType (none, all, sentences, or words).
208+
*/
209+
capitalizationType?: string;
180210
}
181211

182212
/**

‎tns-core-modules/ui/dialogs/dialogs.ios.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { View, ios as iosView } from "../core/view";
55
import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from ".";
6-
import { getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common";
6+
import { getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, capitalizationType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common";
77
import { isString, isDefined, isFunction } from "../../utils/types";
88
import { getRootView } from "../../application";
99

@@ -114,6 +114,23 @@ export function prompt(arg: any): Promise<PromptResult> {
114114

115115
textField = alertController.textFields.firstObject;
116116

117+
if (options) {
118+
switch (options.capitalizationType) {
119+
case capitalizationType.all: {
120+
textField.autocapitalizationType = UITextAutocapitalizationType.AllCharacters; break;
121+
}
122+
case capitalizationType.sentences: {
123+
textField.autocapitalizationType = UITextAutocapitalizationType.Sentences; break;
124+
}
125+
case capitalizationType.words: {
126+
textField.autocapitalizationType = UITextAutocapitalizationType.Words; break;
127+
}
128+
default: {
129+
textField.autocapitalizationType = UITextAutocapitalizationType.None;
130+
}
131+
}
132+
}
133+
117134
addButtonsToAlertController(alertController, options,
118135
(r) => { resolve({ result: r, text: textField.text }); });
119136

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL