Skip to content

Commit 39113f6

Browse files
committed
Fix: Invalid value 500 for property fontWeight in XML
Resolves NativeScript#3175
1 parent b650bbb commit 39113f6

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
2+
<StackLayout>
3+
<Label text="100" style.fontWeight="100" />
4+
<Label text="200" style.fontWeight="200" />
5+
<Label text="300" style.fontWeight="300" />
6+
<Label text="400" style.fontWeight="400" />
7+
<Label text="normal" style.fontWeight="normal" />
8+
<Label text="500" style.fontWeight="500" />
9+
<Label text="600" style.fontWeight="600" />
10+
<Label text="700" style.fontWeight="700" />
11+
<Label text="bold" style.fontWeight="bold" />
12+
<Label text="800" style.fontWeight="800" />
13+
<Label text="900" style.fontWeight="900" />
14+
</StackLayout>
15+
</Page>

apps/app/ui-tests-app/issues/main-page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function pageLoaded(args: EventData) {
1818
examples.set("2661", "issues/issue-2661");
1919
examples.set("3113", "issues/issue-3113");
2020
examples.set("3164", "issues/issue-3164");
21+
examples.set("3175", "issues/issue-3175");
2122

2223
let viewModel = new SubMainPageViewModel(wrapLayout, examples);
2324
page.bindingContext = viewModel;

tests/app/ui/styling/style-properties-tests.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,7 @@ function test_font_shorthand_property(short: string, family: string, size: numbe
529529
TKUnit.assertEqual(testView.style.fontWeight, weight, "style.fontWeight");
530530
TKUnit.assertEqual(testView.style.fontSize, size, "style.fontSize");
531531
}
532-
533532
export function test_setting_font_properties_sets_native_font() {
534-
535533
if (fontModule.ios) {
536534
var basePath = "fonts";
537535
fontModule.ios.registerFont(basePath + "/Roboto-Regular.ttf");
@@ -571,6 +569,22 @@ function test_native_font(style: string, weight: string) {
571569
//TODO: If needed add tests for other platforms
572570
}
573571

572+
export function test_FontWeightsParsedAsNumbersByTheXmlParserAreConvertedToStrings() {
573+
var testView = new buttonModule.Button();
574+
// The XML parser will interpret "100" as a number and feed it to Style, so simulate this here.
575+
(<any>testView.style).fontWeight = 100; TKUnit.assertEqual(testView.style.fontWeight, "100");
576+
(<any>testView.style).fontWeight = 200; TKUnit.assertEqual(testView.style.fontWeight, "200");
577+
(<any>testView.style).fontWeight = 300; TKUnit.assertEqual(testView.style.fontWeight, "300");
578+
(<any>testView.style).fontWeight = 400; TKUnit.assertEqual(testView.style.fontWeight, "400");
579+
(<any>testView.style).fontWeight = "normal"; TKUnit.assertEqual(testView.style.fontWeight, "normal");
580+
(<any>testView.style).fontWeight = 500; TKUnit.assertEqual(testView.style.fontWeight, "500");
581+
(<any>testView.style).fontWeight = 600; TKUnit.assertEqual(testView.style.fontWeight, "600");
582+
(<any>testView.style).fontWeight = 700; TKUnit.assertEqual(testView.style.fontWeight, "700");
583+
(<any>testView.style).fontWeight = "bold"; TKUnit.assertEqual(testView.style.fontWeight, "bold");
584+
(<any>testView.style).fontWeight = 800; TKUnit.assertEqual(testView.style.fontWeight, "800");
585+
(<any>testView.style).fontWeight = 900; TKUnit.assertEqual(testView.style.fontWeight, "900");
586+
}
587+
574588
export var test_setting_button_whiteSpace_normal_sets_native = function () {
575589
var testView = new buttonModule.Button();
576590
testView.style.whiteSpace = "nowrap";

tns-core-modules/ui/styling/style.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ export class Style extends DependencyObservable implements styling.Style {
650650
return this._getValue(fontWeightProperty);
651651
}
652652
set fontWeight(value: string) {
653-
this._setValue(fontWeightProperty, value);
653+
let stringValue = value ? value.toString() : undefined;
654+
this._setValue(fontWeightProperty, stringValue);
654655
}
655656

656657
get font(): string {

0 commit comments

Comments
 (0)