fix: TextField not secure when keyboardType="number" (#5012)

This commit is contained in:
Vasil Chimev
2017-10-31 18:29:39 +02:00
committed by GitHub
parent 32b9ec2159
commit 3e6f465cc8
3 changed files with 40 additions and 5 deletions

View File

@@ -48,7 +48,7 @@ allTests["HTTP"] = httpTests;
## Writing Test Module
The test modules are actually TypeScript modules which export unit tests and hooks as functions following this convention:
* All exported functions which with a `test` prefix are unit-tests.
* All exported functions with a `test` prefix are unit-tests.
* The `setUpModule()` hook is called once - before all the tests in the module.
* The `setUp()` hook is called before each tests.
* The `tearDown()` hook called after each tests.

View File

@@ -317,6 +317,32 @@ export var testSetSecure = function () {
});
}
export var testSetSecureAndKeyboardTypeNumber = function () {
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
var textField = <textFieldModule.TextField>views[0];
textField.secure = true;
textField.keyboardType = "number";
var expectedValue = true;
var actualValue = textFieldTestsNative.getNativeSecure(textField);
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
});
}
export var testSetKeyboardTypeNumberAndSecure = function () {
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
var textField = <textFieldModule.TextField>views[0];
textField.keyboardType = "number";
textField.secure = true;
var expectedValue = true;
var actualValue = textFieldTestsNative.getNativeSecure(textField);
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
});
}
export var testBindSecureDirectlyToModel = function () {
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
var textField = <textFieldModule.TextField>views[0];

View File

@@ -1,4 +1,4 @@
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace } from "./text-field-common";
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace, keyboardTypeProperty } from "./text-field-common";
export * from "./text-field-common";
@@ -14,13 +14,22 @@ export class TextField extends TextFieldBase {
this.notify({ eventName: TextField.returnPressEvent, object: this })
}
[secureProperty.setNative](value: boolean) {
[secureProperty.setNative]() {
this.setSecureAndKeyboardType();
}
[keyboardTypeProperty.setNative]() {
this.setSecureAndKeyboardType();
}
setSecureAndKeyboardType(): void {
let inputType: number;
// Password variations are supported only for Text and Number classes.
if (value) {
if (this.secure) {
if (this.keyboardType === "number") {
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
} else {
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
}