From cd7877dfa0780ffab565d86e14fbb65d12f74aca Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Fri, 13 Jan 2017 11:32:00 +0200 Subject: [PATCH] Text field tests fixed. --- tests/app/testRunner.ts | 2 +- tests/app/ui/text-field/text-field-tests.ts | 8 +++---- .../ui/text-base/text-base.ios.ts | 24 ++++++++++--------- .../ui/text-field/text-field.ios.ts | 24 +++++++++++++++---- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index 566a9e131..6eda752be 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -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"); diff --git a/tests/app/ui/text-field/text-field-tests.ts b/tests/app/ui/text-field/text-field-tests.ts index e94d09bab..44f6a8bdb 100644 --- a/tests/app/ui/text-field/text-field-tests.ts +++ b/tests/app/ui/text-field/text-field-tests.ts @@ -192,7 +192,7 @@ if (platform.device.os === platform.platformNames.ios) { helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array) { var 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) { 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;"); diff --git a/tns-core-modules/ui/text-base/text-base.ios.ts b/tns-core-modules/ui/text-base/text-base.ios.ts index 390a8aef9..5749d8116 100644 --- a/tns-core-modules/ui/text-base/text-base.ios.ts +++ b/tns-core-modules/ui/text-base/text-base.ios.ts @@ -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().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().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; } diff --git a/tns-core-modules/ui/text-field/text-field.ios.ts b/tns-core-modules/ui/text-field/text-field.ios.ts index e78d6836c..d933df7de 100644 --- a/tns-core-modules/ui/text-field/text-field.ios.ts +++ b/tns-core-modules/ui/text-field/text-field.ios.ts @@ -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(); 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 {