UNPKG

10.1 kBJavaScriptView Raw
1import { EditableTextBase as EditableTextBaseCommon, autofillTypeProperty, keyboardTypeProperty, returnKeyTypeProperty, autocapitalizationTypeProperty, autocorrectProperty } from './editable-text-base-common';
2export * from './editable-text-base-common';
3export class EditableTextBase extends EditableTextBaseCommon {
4 dismissSoftInput() {
5 this.nativeTextViewProtected.resignFirstResponder();
6 this.notify({ eventName: EditableTextBase.blurEvent, object: this });
7 }
8 [keyboardTypeProperty.getDefault]() {
9 const keyboardType = this.nativeTextViewProtected.keyboardType;
10 switch (keyboardType) {
11 case 2 /* UIKeyboardType.NumbersAndPunctuation */:
12 return 'number';
13 case 5 /* UIKeyboardType.PhonePad */:
14 return 'phone';
15 case 3 /* UIKeyboardType.URL */:
16 return 'url';
17 case 7 /* UIKeyboardType.EmailAddress */:
18 return 'email';
19 case 4 /* UIKeyboardType.NumberPad */:
20 return 'integer';
21 default:
22 return keyboardType.toString();
23 }
24 }
25 [keyboardTypeProperty.setNative](value) {
26 let newKeyboardType;
27 switch (value) {
28 case 'datetime':
29 newKeyboardType = 2 /* UIKeyboardType.NumbersAndPunctuation */;
30 break;
31 case 'phone':
32 newKeyboardType = 5 /* UIKeyboardType.PhonePad */;
33 break;
34 case 'number':
35 newKeyboardType = 2 /* UIKeyboardType.NumbersAndPunctuation */;
36 break;
37 case 'url':
38 newKeyboardType = 3 /* UIKeyboardType.URL */;
39 break;
40 case 'email':
41 newKeyboardType = 7 /* UIKeyboardType.EmailAddress */;
42 break;
43 case 'integer':
44 newKeyboardType = 4 /* UIKeyboardType.NumberPad */;
45 break;
46 default: {
47 const kt = +value;
48 if (!isNaN(kt)) {
49 newKeyboardType = kt;
50 }
51 else {
52 newKeyboardType = 0 /* UIKeyboardType.Default */;
53 }
54 break;
55 }
56 }
57 this.nativeTextViewProtected.keyboardType = newKeyboardType;
58 }
59 [autofillTypeProperty.setNative](value) {
60 let newTextContentType;
61 switch (value) {
62 case 'phone':
63 newTextContentType = UITextContentTypeTelephoneNumber;
64 break;
65 case 'postalCode':
66 newTextContentType = UITextContentTypePostalCode;
67 break;
68 case 'creditCardNumber':
69 newTextContentType = UITextContentTypeCreditCardNumber;
70 break;
71 case 'email':
72 newTextContentType = UITextContentTypeEmailAddress;
73 break;
74 case 'name':
75 newTextContentType = UITextContentTypeName;
76 break;
77 case 'username':
78 newTextContentType = UITextContentTypeUsername;
79 break;
80 case 'password':
81 newTextContentType = UITextContentTypePassword;
82 break;
83 case 'newPassword':
84 newTextContentType = UITextContentTypeNewPassword;
85 break;
86 case 'oneTimeCode':
87 newTextContentType = UITextContentTypeOneTimeCode;
88 break;
89 case 'none':
90 newTextContentType = null;
91 break;
92 default: {
93 newTextContentType = value;
94 break;
95 }
96 }
97 this.nativeTextViewProtected.textContentType = newTextContentType;
98 }
99 [returnKeyTypeProperty.getDefault]() {
100 const returnKeyType = this.nativeTextViewProtected.returnKeyType;
101 switch (returnKeyType) {
102 case 9 /* UIReturnKeyType.Done */:
103 return 'done';
104 case 1 /* UIReturnKeyType.Go */:
105 return 'go';
106 case 4 /* UIReturnKeyType.Next */:
107 return 'next';
108 case 6 /* UIReturnKeyType.Search */:
109 return 'search';
110 case 7 /* UIReturnKeyType.Send */:
111 return 'send';
112 default:
113 return returnKeyType.toString();
114 }
115 }
116 [returnKeyTypeProperty.setNative](value) {
117 let newValue;
118 switch (value) {
119 case 'done':
120 newValue = 9 /* UIReturnKeyType.Done */;
121 break;
122 case 'go':
123 newValue = 1 /* UIReturnKeyType.Go */;
124 break;
125 case 'next':
126 newValue = 4 /* UIReturnKeyType.Next */;
127 break;
128 case 'search':
129 newValue = 6 /* UIReturnKeyType.Search */;
130 break;
131 case 'send':
132 newValue = 7 /* UIReturnKeyType.Send */;
133 break;
134 default: {
135 const rkt = +value;
136 if (!isNaN(rkt)) {
137 newValue = rkt;
138 }
139 else {
140 newValue = 0 /* UIKeyboardType.Default */;
141 }
142 break;
143 }
144 }
145 this.nativeTextViewProtected.returnKeyType = newValue;
146 }
147 [autocapitalizationTypeProperty.getDefault]() {
148 const autocapitalizationType = this.nativeTextViewProtected.autocapitalizationType;
149 switch (autocapitalizationType) {
150 case 0 /* UITextAutocapitalizationType.None */:
151 return 'none';
152 case 1 /* UITextAutocapitalizationType.Words */:
153 return 'words';
154 case 2 /* UITextAutocapitalizationType.Sentences */:
155 return 'sentences';
156 case 3 /* UITextAutocapitalizationType.AllCharacters */:
157 return 'allcharacters';
158 default:
159 throw new Error('Invalid autocapitalizationType value:' + autocapitalizationType);
160 }
161 }
162 [autocapitalizationTypeProperty.setNative](value) {
163 let newValue;
164 switch (value) {
165 case 'none':
166 newValue = 0 /* UITextAutocapitalizationType.None */;
167 break;
168 case 'words':
169 newValue = 1 /* UITextAutocapitalizationType.Words */;
170 break;
171 case 'sentences':
172 newValue = 2 /* UITextAutocapitalizationType.Sentences */;
173 break;
174 case 'allcharacters':
175 newValue = 3 /* UITextAutocapitalizationType.AllCharacters */;
176 break;
177 default:
178 newValue = 2 /* UITextAutocapitalizationType.Sentences */;
179 break;
180 }
181 this.nativeTextViewProtected.autocapitalizationType = newValue;
182 }
183 [autocorrectProperty.getDefault]() {
184 const autocorrectionType = this.nativeTextViewProtected.autocorrectionType;
185 switch (autocorrectionType) {
186 case 2 /* UITextAutocorrectionType.Yes */:
187 return true;
188 case 1 /* UITextAutocorrectionType.No */:
189 return false;
190 case 0 /* UITextAutocorrectionType.Default */:
191 return autocorrectionType;
192 }
193 }
194 [autocorrectProperty.setNative](value) {
195 let newValue;
196 let spelling;
197 if (typeof value === 'number') {
198 newValue = 0 /* UITextAutocorrectionType.Default */;
199 spelling = 0 /* UITextSpellCheckingType.Default */;
200 }
201 else if (value) {
202 newValue = 2 /* UITextAutocorrectionType.Yes */;
203 spelling = 2 /* UITextSpellCheckingType.Yes */;
204 }
205 else {
206 newValue = 1 /* UITextAutocorrectionType.No */;
207 spelling = 1 /* UITextSpellCheckingType.No */;
208 }
209 this.nativeTextViewProtected.autocorrectionType = newValue;
210 this.nativeTextViewProtected.spellCheckingType = spelling;
211 }
212 setSelection(start, stop) {
213 const view = this.nativeTextViewProtected;
214 if (view) {
215 if (stop !== undefined) {
216 const begin = view.beginningOfDocument;
217 const fromPosition = view.positionFromPositionOffset(begin, start);
218 const toPosition = view.positionFromPositionOffset(begin, stop);
219 view.selectedTextRange = view.textRangeFromPositionToPosition(fromPosition, toPosition);
220 }
221 else {
222 const begin = view.beginningOfDocument;
223 const pos = view.positionFromPositionOffset(begin, start);
224 view.selectedTextRange = view.textRangeFromPositionToPosition(pos, pos);
225 }
226 }
227 }
228}
229export function _updateCharactersInRangeReplacementString(formattedText, rangeLocation, rangeLength, replacementString) {
230 const deletingText = !replacementString;
231 let currentLocation = 0;
232 for (let i = 0, length = formattedText.spans.length; i < length; i++) {
233 const span = formattedText.spans.getItem(i);
234 if (currentLocation <= rangeLocation && rangeLocation < currentLocation + span.text.length) {
235 const newText = splice(span.text, rangeLocation - currentLocation, deletingText ? rangeLength : 0, replacementString);
236 span._setTextInternal(newText);
237 return;
238 }
239 currentLocation += span.text.length;
240 }
241}
242/*
243 * @param {String} value The string to splice.
244 * @param {number} start Index at which to start changing the string.
245 * @param {number} delCount An integer indicating the number of old chars to remove.
246 * @param {string} newSubStr The String that is spliced in.
247 * @return {string} A new string with the spliced substring.function splice(value: string, start: number, delCount: number, newSubStr: string) {
248 */
249function splice(value, start, delCount, newSubStr) {
250 return value.slice(0, start) + newSubStr + value.slice(start + Math.abs(delCount));
251}
252//# sourceMappingURL=index.ios.js.map
\No newline at end of file