From 933356e2a605d9abc423eebc91bd84132875cb56 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 19 Nov 2024 14:06:20 -0800 Subject: [PATCH] Fabric: Fixes custom font of weight is not honored (#47691) Summary: Fixes https://github.com/facebook/react-native/issues/47656 . ## Changelog: [IOS] [FIXED] - Fabric: Fixes custom font of weight is not honored Pull Request resolved: https://github.com/facebook/react-native/pull/47691 Test Plan: Demo in https://github.com/facebook/react-native/issues/47656 Reviewed By: cipolleschi Differential Revision: D66174732 Pulled By: javache fbshipit-source-id: 5e6a8c870d3a13283548c736aed73193f7976bfc --- .../ios/react/renderer/textlayoutmanager/RCTFontUtils.mm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm index e6169c664a0..5f744790a94 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm @@ -170,12 +170,15 @@ UIFont *RCTFontWithFontProperties(RCTFontProperties fontProperties) // Gracefully handle being given a font name rather than font family, for // example: "Helvetica Light Oblique" rather than just "Helvetica". font = [UIFont fontWithName:fontProperties.family size:effectiveFontSize]; - - if (!font) { + if (font) { + fontNames = [UIFont fontNamesForFamilyName:font.familyName]; + } else { // Failback to system font. font = [UIFont systemFontOfSize:effectiveFontSize weight:fontProperties.weight]; } - } else { + } + + if (fontNames.count > 0) { // Get the closest font that matches the given weight for the fontFamily CGFloat closestWeight = INFINITY; for (NSString *name in fontNames) {