fix(ios): custom font not applied correctly in v0.83 #55071
+3
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the font fallback logic in RCTFontUtils.mm to improve code clarity and maintainability. The changes simplify the conditional flow when handling font names that might be font families or specific font names (e.g., "Helvetica Light Oblique" vs "Helvetica").
Changes made:
Removed nested conditional checks and simplified the font fallback logic
Restructured the code to use a cleaner if-else pattern instead of separate conditional blocks
The logic now more clearly shows: if fontNames is empty, try to get font by name; if that fails, fall back to system font; otherwise, proceed with the existing font matching logic
This refactoring maintains the same behavior while making the code easier to read and understand.
Changelog:
[IOS] [CHANGED] - Refactored font fallback logic in RCTFontUtils for improved code clarity
Test Plan:
Existing functionality preserved: All existing font rendering should work exactly as before
Test with font family names: Verify that standard font families like "Helvetica", "Arial" continue to work
Test with specific font names: Verify that specific font names like "Helvetica Light Oblique" are handled correctly
Test fallback behavior: Verify that invalid font names correctly fall back to the system font
Run existing unit tests and integration tests to ensure no regressions
Test on various iOS versions to ensure compatibility
Manual testing:
Create a React Native app with various fontFamily props using both family names and specific font names
Verify text renders correctly in all cases
Verify that invalid font names gracefully fall back to system font without crashes