feat: add integer only keyboard type for text-field and for all editable text components

This commit is contained in:
NickIliev
2019-12-12 10:45:20 +02:00
parent c5b7f439f2
commit 954e1c61b5
7 changed files with 27 additions and 5 deletions

View File

@ -38,7 +38,7 @@ export abstract class EditableTextBase extends TextBase implements EditableTextB
export const placeholderColorProperty = new CssProperty<Style, Color>({ name: "placeholderColor", cssName: "placeholder-color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) }); export const placeholderColorProperty = new CssProperty<Style, Color>({ name: "placeholderColor", cssName: "placeholder-color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
placeholderColorProperty.register(Style); placeholderColorProperty.register(Style);
const keyboardTypeConverter = makeParser<KeyboardType>(makeValidator<KeyboardType>("datetime", "phone", "number", "url", "email")); const keyboardTypeConverter = makeParser<KeyboardType>(makeValidator<KeyboardType>("datetime", "phone", "number", "url", "email", "integer"));
export const keyboardTypeProperty = new Property<EditableTextBase, KeyboardType>({ name: "keyboardType", valueConverter: keyboardTypeConverter }); export const keyboardTypeProperty = new Property<EditableTextBase, KeyboardType>({ name: "keyboardType", valueConverter: keyboardTypeConverter });
keyboardTypeProperty.register(EditableTextBase); keyboardTypeProperty.register(EditableTextBase);

View File

@ -248,8 +248,9 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
[keyboardTypeProperty.getDefault](): number { [keyboardTypeProperty.getDefault](): number {
return this.nativeTextViewProtected.getInputType(); return this.nativeTextViewProtected.getInputType();
} }
[keyboardTypeProperty.setNative](value: "datetime" | "phone" | "number" | "url" | "email" | number) { [keyboardTypeProperty.setNative](value: "datetime" | "phone" | "number" | "url" | "email" | "integer" | number) {
let newInputType; let newInputType;
switch (value) { switch (value) {
case "datetime": case "datetime":
newInputType = android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL; newInputType = android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL;
@ -271,6 +272,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
newInputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; newInputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
break; break;
case "integer":
newInputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
break;
default: default:
newInputType = value; newInputType = value;
break; break;

View File

@ -65,7 +65,7 @@ export class EditableTextBase extends TextBase {
//@endprivate //@endprivate
} }
export type KeyboardType = "datetime" | "phone" | "number" | "url" | "email"; export type KeyboardType = "datetime" | "phone" | "number" | "url" | "email" | "integer";
export type ReturnKeyType = "done" | "next" | "go" | "search" | "send"; export type ReturnKeyType = "done" | "next" | "go" | "search" | "send";
export type UpdateTextTrigger = "focusLost" | "textChanged"; export type UpdateTextTrigger = "focusLost" | "textChanged";
export type AutocapitalizationType = "none" | "words" | "sentences" | "allcharacters"; export type AutocapitalizationType = "none" | "words" | "sentences" | "allcharacters";

View File

@ -13,7 +13,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
this.notify({ eventName: EditableTextBase.blurEvent, object: this }); this.notify({ eventName: EditableTextBase.blurEvent, object: this });
} }
[keyboardTypeProperty.getDefault](): "datetime" | "phone" | "number" | "url" | "email" | string { [keyboardTypeProperty.getDefault](): "datetime" | "phone" | "number" | "url" | "email" | "integer" | string {
let keyboardType = this.nativeTextViewProtected.keyboardType; let keyboardType = this.nativeTextViewProtected.keyboardType;
switch (keyboardType) { switch (keyboardType) {
case UIKeyboardType.NumbersAndPunctuation: case UIKeyboardType.NumbersAndPunctuation:
@ -28,11 +28,14 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
case UIKeyboardType.EmailAddress: case UIKeyboardType.EmailAddress:
return "email"; return "email";
case UIKeyboardType.NumberPad:
return "integer";
default: default:
return keyboardType.toString(); return keyboardType.toString();
} }
} }
[keyboardTypeProperty.setNative](value: "datetime" | "phone" | "number" | "url" | "email" | string) { [keyboardTypeProperty.setNative](value: "datetime" | "phone" | "number" | "url" | "email" | "integer" | string) {
let newKeyboardType: UIKeyboardType; let newKeyboardType: UIKeyboardType;
switch (value) { switch (value) {
case "datetime": case "datetime":
@ -55,6 +58,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
newKeyboardType = UIKeyboardType.EmailAddress; newKeyboardType = UIKeyboardType.EmailAddress;
break; break;
case "integer":
newKeyboardType = UIKeyboardType.NumberPad;
break;
default: default:
let kt = +value; let kt = +value;
if (!isNaN(kt)) { if (!isNaN(kt)) {

View File

@ -73,6 +73,12 @@ export module KeyboardType {
* iOS: [UIKeyboardTypeEmailAddress](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) * iOS: [UIKeyboardTypeEmailAddress](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
*/ */
export const email: BaseKeyboardType export const email: BaseKeyboardType
/**
* Android: [TYPE_CLASS_NUMBER](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_NUMBER | [TYPE_NUMBER_VARIATION_PASSWORD](android type_text_variation_password))
* iOS: [UIKeyboardTypeNumberPad](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
*/
export const integer: BaseKeyboardType
} }
/** /**

View File

@ -7,6 +7,7 @@ export module KeyboardType {
export const number = "number"; export const number = "number";
export const url = "url"; export const url = "url";
export const email = "email"; export const email = "email";
export const integer = "integer";
} }
export module ReturnKeyType { export module ReturnKeyType {

View File

@ -77,6 +77,9 @@ export class TextField extends TextFieldBase {
case "email": case "email":
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
break; break;
case "integer":
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
break;
default: default:
break; break;
} }