mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(TextField): decimal keyboardType (#10789)
This commit is contained in:
@@ -339,6 +339,32 @@ export var testSetKeyboardTypeNumberAndSecure = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export var testSetSecureAndKeyboardTypeDecimal = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
||||||
|
var textField = <TextField>views[0];
|
||||||
|
|
||||||
|
textField.secure = true;
|
||||||
|
textField.keyboardType = 'decimal';
|
||||||
|
|
||||||
|
var expectedValue = true;
|
||||||
|
var actualValue = getNativeSecure(textField);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, 'Actual: ' + actualValue + '; Expected: ' + expectedValue);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export var testSetKeyboardTypeDecimalAndSecure = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
||||||
|
var textField = <TextField>views[0];
|
||||||
|
|
||||||
|
textField.keyboardType = 'decimal';
|
||||||
|
textField.secure = true;
|
||||||
|
|
||||||
|
var expectedValue = true;
|
||||||
|
var actualValue = getNativeSecure(textField);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, 'Actual: ' + actualValue + '; Expected: ' + expectedValue);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export var testBindSecureDirectlyToModel = function () {
|
export var testBindSecureDirectlyToModel = function () {
|
||||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
||||||
var textField = <TextField>views[0];
|
var textField = <TextField>views[0];
|
||||||
|
|||||||
@@ -40,11 +40,12 @@ export namespace CoreTypes {
|
|||||||
unit: 'px',
|
unit: 'px',
|
||||||
};
|
};
|
||||||
|
|
||||||
export type KeyboardInputType = 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer';
|
export type KeyboardInputType = 'datetime' | 'phone' | 'number' | 'decimal' | 'url' | 'email' | 'integer';
|
||||||
export namespace KeyboardType {
|
export namespace KeyboardType {
|
||||||
export const datetime = 'datetime';
|
export const datetime = 'datetime';
|
||||||
export const phone = 'phone';
|
export const phone = 'phone';
|
||||||
export const number = 'number';
|
export const number = 'number';
|
||||||
|
export const decimal = 'decimal';
|
||||||
export const url = 'url';
|
export const url = 'url';
|
||||||
export const email = 'email';
|
export const email = 'email';
|
||||||
export const integer = 'integer';
|
export const integer = 'integer';
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export const placeholderColorProperty = new CssProperty<Style, Color>({
|
|||||||
});
|
});
|
||||||
placeholderColorProperty.register(Style);
|
placeholderColorProperty.register(Style);
|
||||||
|
|
||||||
const keyboardTypeConverter = makeParser<CoreTypes.KeyboardInputType>(makeValidator<CoreTypes.KeyboardInputType>(CoreTypes.KeyboardType.datetime, CoreTypes.KeyboardType.phone, CoreTypes.KeyboardType.number, CoreTypes.KeyboardType.url, CoreTypes.KeyboardType.email, CoreTypes.KeyboardType.integer), true);
|
const keyboardTypeConverter = makeParser<CoreTypes.KeyboardInputType>(makeValidator<CoreTypes.KeyboardInputType>(CoreTypes.KeyboardType.datetime, CoreTypes.KeyboardType.phone, CoreTypes.KeyboardType.number, CoreTypes.KeyboardType.decimal, CoreTypes.KeyboardType.url, CoreTypes.KeyboardType.email, CoreTypes.KeyboardType.integer), true);
|
||||||
|
|
||||||
export const autofillTypeProperty = new Property<EditableTextBase, CoreTypes.AutofillType>({ name: 'autofillType' });
|
export const autofillTypeProperty = new Property<EditableTextBase, CoreTypes.AutofillType>({ name: 'autofillType' });
|
||||||
autofillTypeProperty.register(EditableTextBase);
|
autofillTypeProperty.register(EditableTextBase);
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ 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' | 'integer' | number) {
|
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'decimal' | 'url' | 'email' | 'integer' | number) {
|
||||||
let newInputType;
|
let newInputType;
|
||||||
|
|
||||||
switch (value) {
|
switch (value) {
|
||||||
@@ -220,6 +220,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
|||||||
newInputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
newInputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'decimal':
|
||||||
|
newInputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'url':
|
case 'url':
|
||||||
newInputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
newInputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
|||||||
return keyboardType.toString();
|
return keyboardType.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer' | string) {
|
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'decimal' | 'url' | 'email' | 'integer' | string) {
|
||||||
let newKeyboardType: UIKeyboardType;
|
let newKeyboardType: UIKeyboardType;
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 'datetime':
|
case 'datetime':
|
||||||
@@ -49,6 +49,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
|||||||
newKeyboardType = UIKeyboardType.NumbersAndPunctuation;
|
newKeyboardType = UIKeyboardType.NumbersAndPunctuation;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'decimal':
|
||||||
|
newKeyboardType = UIKeyboardType.DecimalPad;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'url':
|
case 'url':
|
||||||
newKeyboardType = UIKeyboardType.URL;
|
newKeyboardType = UIKeyboardType.URL;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ export class TextField extends TextFieldBase {
|
|||||||
case 'number':
|
case 'number':
|
||||||
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||||
break;
|
break;
|
||||||
|
case 'decimal':
|
||||||
|
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
break;
|
||||||
case 'url':
|
case 'url':
|
||||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user