Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fontWeight regression #15825

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions React/Views/RCTFont.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@

#endif

static NSArray *fontNameOrdering = [NSArray arrayWithObjects:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's initialize this array inside the dispatch once block, just like the nameToWeight dictionary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use @[a, b, c] shorthand to initialize the array instead of arrayWithObjects.

@"normal",
@"ultralight",
@"thin",
@"light",
@"regular",
@"medium",
@"semibold",
@"bold",
@"heavy",
@"black",
nil];

typedef CGFloat RCTFontWeight;
static RCTFontWeight weightOfFont(UIFont *font)
{
Expand All @@ -41,7 +54,6 @@ static RCTFontWeight weightOfFont(UIFont *font)
dispatch_once(&onceToken, ^{
nameToWeight = @{
@"normal": @(UIFontWeightRegular),
@"bold": @(UIFontWeightBold),
@"ultralight": @(UIFontWeightUltraLight),
@"thin": @(UIFontWeightThin),
@"light": @(UIFontWeightLight),
Expand All @@ -51,10 +63,10 @@ static RCTFontWeight weightOfFont(UIFont *font)
@"bold": @(UIFontWeightBold),
@"heavy": @(UIFontWeightHeavy),
@"black": @(UIFontWeightBlack),
};
};
});

for (NSString *name in nameToWeight) {
for (NSString *name in fontNameOrdering) {
if ([font.fontName.lowercaseString hasSuffix:name]) {
return [nameToWeight[name] doubleValue];
}
Expand Down