From 4254a62ffe1cb13781988d088b2e112e58629d75 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Fri, 31 Jul 2026 11:24:31 +0200 Subject: [PATCH] fix: consider extralight fonts in RCTGetFontWeight --- 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 675f40c3131c..b9c1ad26530f 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 fc686c65f250..db93a4fd8567 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m @@ -49,6 +49,25 @@ - (void)testWeight } } +- (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 { {