mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Text field tests fixed.
This commit is contained in:
@ -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");
|
||||
|
@ -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;");
|
||||
|
@ -283,6 +283,7 @@ function setTextDecorationAndTransform(text: string, nativeView: UITextField | U
|
||||
|
||||
function createNSMutableAttributedString(formattedString: FormattedString): NSMutableAttributedString {
|
||||
let mas = NSMutableAttributedString.alloc().init();
|
||||
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);
|
||||
@ -296,5 +297,6 @@ function createNSMutableAttributedString(formattedString: FormattedString): NSMu
|
||||
mas.insertAttributedStringAtIndex(nsAttributedString, spanStart);
|
||||
spanStart += spanLength;
|
||||
}
|
||||
}
|
||||
return mas;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user