Skip to content

Commit 4254a62

Browse files
committed
fix: consider extralight fonts in RCTGetFontWeight
1 parent 1208178 commit 4254a62

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

packages/react-native/React/Views/RCTFont.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ RCTFontWeight RCTGetFontWeight(UIFont *font)
2424
weightSuffixes = @[
2525
@"normal",
2626
@"ultralight",
27+
@"extralight",
2728
@"thin",
2829
@"light",
2930
@"regular",
@@ -39,6 +40,7 @@ RCTFontWeight RCTGetFontWeight(UIFont *font)
3940
fontWeights = @[
4041
@(UIFontWeightRegular),
4142
@(UIFontWeightUltraLight),
43+
@(UIFontWeightUltraLight),
4244
@(UIFontWeightThin),
4345
@(UIFontWeightLight),
4446
@(UIFontWeightRegular),

packages/rn-tester/RNTesterUnitTests/RCTFontTests.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ - (void)testWeight
4949
}
5050
}
5151

52+
- (void)testWeightFromFontName
53+
{
54+
// "ExtraLight" and "UltraLight" name the same weight (OpenType usWeightClass 200).
55+
{
56+
UIFont *font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:14];
57+
XCTAssertEqual(RCTGetFontWeight(font), UIFontWeightUltraLight);
58+
}
59+
#if !TARGET_OS_TV
60+
{
61+
UIFont *font = [UIFont fontWithName:@"Seravek-ExtraLight" size:14];
62+
XCTAssertEqual(RCTGetFontWeight(font), UIFontWeightUltraLight);
63+
}
64+
{
65+
UIFont *font = [UIFont fontWithName:@"Seravek-Light" size:14];
66+
XCTAssertEqual(RCTGetFontWeight(font), UIFontWeightLight);
67+
}
68+
#endif
69+
}
70+
5271
- (void)testSize
5372
{
5473
{

0 commit comments

Comments
 (0)