Skip to content

Commit 89efa1a

Browse files
danilobuergerfacebook-github-bot
authored andcommitted
Only find closest font if system font was not found (#32482)
Summary: Before f951da9 finding a system font used to return early. In order to allow variants, the referenced patch removed the early return so that variants could be applied later. However, there is no need to find the closest font as we already selected the proper system font. This also fixes a bug with setting a custom font handler via RCTSetDefaultFontHandler whos return could get overwritten by the closest font search. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Respect RCTSetDefaultFontHandler chosen font Pull Request resolved: #32482 Reviewed By: ShikaSD Differential Revision: D33844138 Pulled By: cortinico fbshipit-source-id: 05c01fc358cd19f8be342218cdba944b303073ed
1 parent 384e1a0 commit 89efa1a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

React/Views/RCTFont.mm

+11-9
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,18 @@ + (UIFont *)updateFont:(UIFont *)font
355355
}
356356
}
357357

358-
// Get the closest font that matches the given weight for the fontFamily
359-
CGFloat closestWeight = INFINITY;
360358
NSArray<NSString *> *names = fontNamesForFamilyName(familyName);
361-
for (NSString *name in names) {
362-
UIFont *match = [UIFont fontWithName:name size:fontSize];
363-
if (isItalic == isItalicFont(match) && isCondensed == isCondensedFont(match)) {
364-
CGFloat testWeight = weightOfFont(match);
365-
if (ABS(testWeight - fontWeight) < ABS(closestWeight - fontWeight)) {
366-
font = match;
367-
closestWeight = testWeight;
359+
if (!didFindFont) {
360+
// Get the closest font that matches the given weight for the fontFamily
361+
CGFloat closestWeight = INFINITY;
362+
for (NSString *name in names) {
363+
UIFont *match = [UIFont fontWithName:name size:fontSize];
364+
if (isItalic == isItalicFont(match) && isCondensed == isCondensedFont(match)) {
365+
CGFloat testWeight = weightOfFont(match);
366+
if (ABS(testWeight - fontWeight) < ABS(closestWeight - fontWeight)) {
367+
font = match;
368+
closestWeight = testWeight;
369+
}
368370
}
369371
}
370372
}

0 commit comments

Comments
 (0)