MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / prompt

Function prompt

packages/core/ui/dialogs/index.ios.ts:133–213  ·  view source on GitHub ↗
(...args)

Source from the content-addressed store, hash-verified

131}
132
133export function prompt(...args): Promise<PromptResult> {
134 let options: PromptOptions;
135
136 const defaultOptions = {
137 title: DialogStrings.PROMPT,
138 okButtonText: DialogStrings.OK,
139 cancelButtonText: DialogStrings.CANCEL,
140 inputType: inputType.text,
141 };
142 const arg = args[0];
143 if (args.length === 1) {
144 if (isString(arg)) {
145 options = defaultOptions;
146 options.message = arg;
147 } else {
148 options = arg;
149 }
150 } else if (args.length === 2) {
151 if (isString(arg) && isString(args[1])) {
152 options = defaultOptions;
153 options.message = arg;
154 options.defaultText = args[1];
155 }
156 }
157
158 return new Promise<PromptResult>((resolve, reject) => {
159 try {
160 const alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert);
161
162 alertController.addTextFieldWithConfigurationHandler((arg: UITextField) => {
163 arg.text = isString(options.defaultText) ? options.defaultText : '';
164 arg.secureTextEntry = options && options.inputType === inputType.password;
165
166 if (options && options.inputType === inputType.email) {
167 arg.keyboardType = UIKeyboardType.EmailAddress;
168 } else if (options && options.inputType === inputType.number) {
169 arg.keyboardType = UIKeyboardType.NumberPad;
170 } else if (options && options.inputType === inputType.decimal) {
171 arg.keyboardType = UIKeyboardType.DecimalPad;
172 } else if (options && options.inputType === inputType.phone) {
173 arg.keyboardType = UIKeyboardType.PhonePad;
174 }
175
176 const color = getTextFieldColor();
177 if (color) {
178 arg.textColor = arg.tintColor = color.ios;
179 }
180 });
181
182 const textField: UITextField = alertController.textFields.firstObject;
183
184 if (options) {
185 switch (options.capitalizationType) {
186 case capitalizationType.all: {
187 textField.autocapitalizationType = UITextAutocapitalizationType.AllCharacters;
188 break;
189 }
190 case capitalizationType.sentences: {

Callers

nothing calls this directly

Calls 5

isStringFunction · 0.90
getTextFieldColorFunction · 0.90
showUIAlertControllerFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected