From 3b5d0a652695f0c370fd5dbdd488a37f2c647f9f Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Mon, 3 Aug 2026 03:27:03 -0700 Subject: [PATCH] fix: consider extralight fonts in RCTGetFontWeight (#57775) Summary: `RCTGetFontWeight`, as the name suggests, gets a UIFontWeight given the font names. Some font names are called `extralight` which is the same weight as the already-covered `ultralight -> UIFontWeightUltraLight` case. However, they'd incorrectly be classified as `UIFontWeightLight`. This PR fixes that. Note that the `extrabold` case was already covered. ## Changelog: [iOS] [FIXED] - correctly classify extralight fonts as `UIFontWeightUltraLight` in `RCTGetFontWeight` Pull Request resolved: https://github.com/react/react-native/pull/57775 Test Plan: - green CI Reviewed By: javache Differential Revision: D114475029 Pulled By: fabriziocucci fbshipit-source-id: 896fd4ba7f06e27aeb5a8faa1884fe6b4dba2a27 --- packages/react-native/React/Views/RCTFont.mm | 2 ++ .../RNTesterUnitTests/RCTFontTests.m | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/react-native/React/Views/RCTFont.mm b/packages/react-native/React/Views/RCTFont.mm index 675f40c3131..b9c1ad26530 100644 --- a/packages/react-native/React/Views/RCTFont.mm +++ b/packages/react-native/React/Views/RCTFont.mm @@ -24,6 +24,7 @@ RCTFontWeight RCTGetFontWeight(UIFont *font) weightSuffixes = @[ @"normal", @"ultralight", + @"extralight", @"thin", @"light", @"regular", @@ -39,6 +40,7 @@ RCTFontWeight RCTGetFontWeight(UIFont *font) fontWeights = @[ @(UIFontWeightRegular), @(UIFontWeightUltraLight), + @(UIFontWeightUltraLight), @(UIFontWeightThin), @(UIFontWeightLight), @(UIFontWeightRegular), diff --git a/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m b/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m index fc686c65f25..db93a4fd856 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m @@ -49,6 +49,25 @@ } } +- (void)testWeightFromFontName +{ + // "ExtraLight" and "UltraLight" name the same weight (OpenType usWeightClass 200). + { + UIFont *font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:14]; + XCTAssertEqual(RCTGetFontWeight(font), UIFontWeightUltraLight); + } +#if !TARGET_OS_TV + { + UIFont *font = [UIFont fontWithName:@"Seravek-ExtraLight" size:14]; + XCTAssertEqual(RCTGetFontWeight(font), UIFontWeightUltraLight); + } + { + UIFont *font = [UIFont fontWithName:@"Seravek-Light" size:14]; + XCTAssertEqual(RCTGetFontWeight(font), UIFontWeightLight); + } +#endif +} + - (void)testSize { {