Text field tests fixed.

This commit is contained in:
Nedyalko Nikolov
2017-01-13 11:32:00 +02:00
parent b72cdb2be6
commit cd7877dfa0
4 changed files with 38 additions and 20 deletions

View File

@ -84,7 +84,7 @@ allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests");
// allTests["PAGE"] = require("./ui/page/page-tests");
// allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
// allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests");
// allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests");
allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests");
allTests["TEXT-VIEW"] = require("./ui/text-view/text-view-tests");
allTests["LIST-PICKER"] = require("./ui/list-picker/list-picker-tests");
allTests["DATE-PICKER"] = require("./ui/date-picker/date-picker-tests");

View File

@ -192,7 +192,7 @@ if (platform.device.os === platform.platformNames.ios) {
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
var textField = <textFieldModule.TextField>views[0];
textField.color = new colorModule.Color("red");
TKUnit.assertEqual(textField.color.ios.CGColor, textField.ios.tintColor.CGColor, "textField.color");
TKUnit.assertEqual(textField.color.ios.CGColor, textField.ios.textColor.CGColor, "textField.color");
});
}
}
@ -540,9 +540,9 @@ export function test_IntegrationTest_Transform_Decoration_Spacing_WithoutFormatt
let view = new textFieldModule.TextField();
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
TKUnit.assertEqual(view.text, "", "Text");
TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.none, "TextTransform");
TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.none, "TextDecoration");
TKUnit.assertTrue(isNaN(view.style.letterSpacing), "LetterSpacing");
TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.none, "TextTransform default value");
TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.none, "TextDecoration default value");
TKUnit.assertTrue(view.style.letterSpacing === 0, "LetterSpacing default value");
view.text = "NormalText";
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;");

View File

@ -283,18 +283,20 @@ function setTextDecorationAndTransform(text: string, nativeView: UITextField | U
function createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
let mas = NSMutableAttributedString.alloc().init();
for (let i = 0, spanStart = 0, spanLength = 0, length = formattedString.spans.length, spanText = ""; i < length; i++) {
let span = formattedString.spans.getItem(i);
spanText = toUIString(span.text);
spanLength = spanText.length;
span.updateSpanModifiers(formattedString);
let attrDict = NSMutableDictionary.alloc<string, any>().init();
for (let p = 0; p < span.spanModifiers.length; p++) {
attrDict.setObjectForKey(span.spanModifiers[p].value, span.spanModifiers[p].key);
if (formattedString) {
for (let i = 0, spanStart = 0, spanLength = 0, length = formattedString.spans.length, spanText = ""; i < length; i++) {
let span = formattedString.spans.getItem(i);
spanText = toUIString(span.text);
spanLength = spanText.length;
span.updateSpanModifiers(formattedString);
let attrDict = NSMutableDictionary.alloc<string, any>().init();
for (let p = 0; p < span.spanModifiers.length; p++) {
attrDict.setObjectForKey(span.spanModifiers[p].value, span.spanModifiers[p].key);
}
let nsAttributedString = NSMutableAttributedString.alloc().initWithStringAttributes(String(spanText), attrDict);
mas.insertAttributedStringAtIndex(nsAttributedString, spanStart);
spanStart += spanLength;
}
let nsAttributedString = NSMutableAttributedString.alloc().initWithStringAttributes(String(spanText), attrDict);
mas.insertAttributedStringAtIndex(nsAttributedString, spanStart);
spanStart += spanLength;
}
return mas;
}

View File

@ -132,6 +132,7 @@ export class TextField extends TextFieldBase {
let weakRef = new WeakRef(this);
this._ios = UITextFieldImpl.initWithOwner(weakRef);
this._delegate = UITextFieldDelegateImpl.initWithOwner(weakRef);
this.nativeView = this._ios;
}
public onLoaded() {
@ -152,7 +153,13 @@ export class TextField extends TextFieldBase {
return this.nativeView.placeholder;
}
set [hintProperty.native](value: string) {
this.nativeView.placeholder = value + '';
let stringValue;
if (value === null || value === void 0) {
stringValue = "";
} else {
stringValue = value + "";
}
this.nativeView.placeholder = stringValue;
}
get [secureProperty.native](): boolean {
@ -166,7 +173,7 @@ export class TextField extends TextFieldBase {
// return this.nativeView.tintColor;
return this.nativeView.textColor;
}
set [colorProperty.native](value: UIColor) {
set [colorProperty.native](value: UIColor | Color) {
// NOTE: Do we need this code? We have placeholderColor.
// let nativeValue = this.nativeView;
// if (this.isShowingHint && value) {
@ -175,7 +182,8 @@ export class TextField extends TextFieldBase {
// nativeValue.textColor = value;
// nativeValue.tintColor = value;
// }
this.nativeView.textColor = value;
let color = value instanceof Color ? value.ios : value;
this.nativeView.textColor = color;
}
get [placeholderColorProperty.native](): UIColor {
@ -185,7 +193,15 @@ export class TextField extends TextFieldBase {
let nativeView = this.nativeView;
let colorAttibutes = NSMutableDictionary.new<string, any>();
colorAttibutes.setValueForKey(value instanceof Color ? value.ios : value, NSForegroundColorAttributeName);
nativeView.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(nativeView.placeholder || "", colorAttibutes);
let stringValue;
if (nativeView.placeholder === null || nativeView.placeholder === void 0) {
// we do not use empty string since initWithStringAttributes does not return proper value and
// nativeView.attributedPlaceholder will be null
stringValue = " ";
} else {
stringValue = nativeView.placeholder + "";
}
nativeView.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, colorAttibutes);
}
get [paddingTopProperty.native](): Length {