Skip to content

Commit cfbb718

Browse files
authored
Fix italic font style on new arch ios (#171)
1 parent 4320a37 commit cfbb718

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,22 @@ static UIFontDescriptorSystemDesign RCTGetFontDescriptorSystemDesign(NSString *f
337337
if (rawFontFamilies.count >= 1) {
338338
NSArray *updatedFontNames = fontNames;
339339

340-
for (NSString *name in rawFontFamilies) {
340+
for (NSString *rawName in rawFontFamilies) {
341+
// Trim surrounding whitespace so tokens like " CustomFont-Bold"
342+
// produced by `, ` separators still match via -fontWithName:
343+
NSString *name = [rawName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
344+
if (name.length == 0) {
345+
continue;
346+
}
341347
UIFont *font = [UIFont fontWithName:name size:effectiveFontSize];
342348
if (font) {
343-
updatedFontNames = [updatedFontNames arrayByAddingObject:font.fontName];
349+
// Expand to all faces of the resolved family so the candidate loop
350+
// below can pick italic/weighted variants. Mirrors what the
351+
// single-name path does
352+
updatedFontNames = [updatedFontNames arrayByAddingObjectsFromArray:
353+
[UIFont fontNamesForFamilyName:font.familyName]];
354+
// Default the weight to the first resolved face when not explicitly set from fontProperties.weight
355+
fontWeight = fontWeight ?: RCTGetFontWeight(font);
344356
}
345357
}
346358

0 commit comments

Comments
 (0)