mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Span colors fixed to accept known colors
This commit is contained in:
@ -66,4 +66,23 @@ export var test_FormattedTextProperty_IsChanged_When_SpanIsChanged = function ()
|
|||||||
|
|
||||||
TKUnit.assert(formattedTextChanged === true, "FormattedText property is not changed.");
|
TKUnit.assert(formattedTextChanged === true, "FormattedText property is not changed.");
|
||||||
TKUnit.assert(formattedString.spans.getItem(0).fontSize === expectedValue, "FormattedString internal span is not changed as expected");
|
TKUnit.assert(formattedString.spans.getItem(0).fontSize === expectedValue, "FormattedString internal span is not changed as expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
export var test_FormattedTextProperty_DoNotCrash_When_KnownColorIsSetForForegroundColor = function () {
|
||||||
|
var formattedString = new formattedStringModule.FormattedString();
|
||||||
|
var expectedValue1 = "red";
|
||||||
|
var expectedValue2 = "blue";
|
||||||
|
|
||||||
|
var firstSpan = new spanModule.Span();
|
||||||
|
firstSpan.foregroundColor = <any>expectedValue1;
|
||||||
|
firstSpan.text = "LoremIpsum1";
|
||||||
|
formattedString.spans.push(firstSpan);
|
||||||
|
|
||||||
|
var secondSpan = new spanModule.Span();
|
||||||
|
secondSpan.backgroundColor = <any>expectedValue2;
|
||||||
|
secondSpan.text = "LoremIpsum2";
|
||||||
|
formattedString.spans.push(secondSpan);
|
||||||
|
|
||||||
|
TKUnit.assertEqual(formattedString.spans.getItem(0).foregroundColor.name, expectedValue1);
|
||||||
|
TKUnit.assertEqual(formattedString.spans.getItem(1).backgroundColor.name, expectedValue2);
|
||||||
}
|
}
|
@ -49,8 +49,8 @@ export class Span extends bindable.Bindable implements definition.Span, view.App
|
|||||||
|
|
||||||
private _getColorValue(value: any): colorModule.Color {
|
private _getColorValue(value: any): colorModule.Color {
|
||||||
var result;
|
var result;
|
||||||
if (types.isString(value) && (<any>value).indexOf("#") === 0) {
|
if (types.isString(value) && colorModule.Color.isValid(value)) {
|
||||||
result = new colorModule.Color(<any>value);
|
result = new colorModule.Color(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = value;
|
result = value;
|
||||||
|
Reference in New Issue
Block a user