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["PAGE"] = require("./ui/page/page-tests");
// allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests"); // allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests");
// allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-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["TEXT-VIEW"] = require("./ui/text-view/text-view-tests");
allTests["LIST-PICKER"] = require("./ui/list-picker/list-picker-tests"); allTests["LIST-PICKER"] = require("./ui/list-picker/list-picker-tests");
allTests["DATE-PICKER"] = require("./ui/date-picker/date-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>) { helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
var textField = <textFieldModule.TextField>views[0]; var textField = <textFieldModule.TextField>views[0];
textField.color = new colorModule.Color("red"); 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(); let view = new textFieldModule.TextField();
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) { helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
TKUnit.assertEqual(view.text, "", "Text"); TKUnit.assertEqual(view.text, "", "Text");
TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.none, "TextTransform"); TKUnit.assertEqual(view.style.textTransform, enums.TextTransform.none, "TextTransform default value");
TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.none, "TextDecoration"); TKUnit.assertEqual(view.style.textDecoration, enums.TextDecoration.none, "TextDecoration default value");
TKUnit.assertTrue(isNaN(view.style.letterSpacing), "LetterSpacing"); TKUnit.assertTrue(view.style.letterSpacing === 0, "LetterSpacing default value");
view.text = "NormalText"; view.text = "NormalText";
view.setInlineStyle("text-transform: uppercase; text-decoration: underline; letter-spacing: 1;"); 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 { function createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
let mas = NSMutableAttributedString.alloc().init(); let mas = NSMutableAttributedString.alloc().init();
for (let i = 0, spanStart = 0, spanLength = 0, length = formattedString.spans.length, spanText = ""; i < length; i++) { if (formattedString) {
let span = formattedString.spans.getItem(i); for (let i = 0, spanStart = 0, spanLength = 0, length = formattedString.spans.length, spanText = ""; i < length; i++) {
spanText = toUIString(span.text); let span = formattedString.spans.getItem(i);
spanLength = spanText.length; spanText = toUIString(span.text);
span.updateSpanModifiers(formattedString); spanLength = spanText.length;
let attrDict = NSMutableDictionary.alloc<string, any>().init(); span.updateSpanModifiers(formattedString);
for (let p = 0; p < span.spanModifiers.length; p++) { let attrDict = NSMutableDictionary.alloc<string, any>().init();
attrDict.setObjectForKey(span.spanModifiers[p].value, span.spanModifiers[p].key); 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; return mas;
} }

View File

@ -132,6 +132,7 @@ export class TextField extends TextFieldBase {
let weakRef = new WeakRef(this); let weakRef = new WeakRef(this);
this._ios = UITextFieldImpl.initWithOwner(weakRef); this._ios = UITextFieldImpl.initWithOwner(weakRef);
this._delegate = UITextFieldDelegateImpl.initWithOwner(weakRef); this._delegate = UITextFieldDelegateImpl.initWithOwner(weakRef);
this.nativeView = this._ios;
} }
public onLoaded() { public onLoaded() {
@ -152,7 +153,13 @@ export class TextField extends TextFieldBase {
return this.nativeView.placeholder; return this.nativeView.placeholder;
} }
set [hintProperty.native](value: string) { 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 { get [secureProperty.native](): boolean {
@ -166,7 +173,7 @@ export class TextField extends TextFieldBase {
// return this.nativeView.tintColor; // return this.nativeView.tintColor;
return this.nativeView.textColor; return this.nativeView.textColor;
} }
set [colorProperty.native](value: UIColor) { set [colorProperty.native](value: UIColor | Color) {
// NOTE: Do we need this code? We have placeholderColor. // NOTE: Do we need this code? We have placeholderColor.
// let nativeValue = this.nativeView; // let nativeValue = this.nativeView;
// if (this.isShowingHint && value) { // if (this.isShowingHint && value) {
@ -175,7 +182,8 @@ export class TextField extends TextFieldBase {
// nativeValue.textColor = value; // nativeValue.textColor = value;
// nativeValue.tintColor = value; // nativeValue.tintColor = value;
// } // }
this.nativeView.textColor = value; let color = value instanceof Color ? value.ios : value;
this.nativeView.textColor = color;
} }
get [placeholderColorProperty.native](): UIColor { get [placeholderColorProperty.native](): UIColor {
@ -185,7 +193,15 @@ export class TextField extends TextFieldBase {
let nativeView = this.nativeView; let nativeView = this.nativeView;
let colorAttibutes = NSMutableDictionary.new<string, any>(); let colorAttibutes = NSMutableDictionary.new<string, any>();
colorAttibutes.setValueForKey(value instanceof Color ? value.ios : value, NSForegroundColorAttributeName); 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 { get [paddingTopProperty.native](): Length {