fix(theme): keep font weights with the System family on Android - #1930
Open
bataevvlad wants to merge 2 commits into
Open
bataevvlad wants to merge 2 commits into
bataevvlad wants to merge 2 commits into
Conversation
React Native Android treats any fontFamily as a custom family and rounds fontWeight to regular or bold, so 500/600 text with the default System family rendered regular. Resolve System to no family on Android so the platform font keeps the numeric weight; iOS and custom families are unchanged.
resolvePlatformFontFamily takes the platform as a parameter, so its spec covers Android and iOS without redefining Platform.OS for the whole suite. StyleService.createThemedEntry calls it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On Android every text with weight
500or600renders regular:s1/s2subtitles, labels, radio and checkbox text, theAvatarinitials from #1926. iOS shows them semibold.The Eva and Material mappings set
text-font-family: "System". React Native Android does not treatSystemas the platform font: anyfontFamilyname goes throughReactFontManager.getTypeface, which looks up the family bynearestStyle(only regular or bold,weight < 700-> regular) and falls back toTypeface.create(name, style). The numeric weight is only kept whenfontFamilyis unset (ReactTypefaceUtils.applyStyles,typefaceStyle.apply(Typeface.DEFAULT)). So600became400, while700+still looked bold.This is a different cause from #1793 (custom fonts registered with only a regular face), which stays documented in the branding guide.
Fix
theme/style/platformFontFamily.ts:resolvePlatformFontFamily(key, value, os = Platform.OS)resolves a*fontFamilyvalue ofSystemtoundefinedon Android.StyleService.createThemedEntry(every mapping andStyleService.createstyle goes through it) calls it. The key stays, so a later consumer style still overrides as before; iOS and custom families are unchanged.FalsyText's fast path checks that the style has afontFamilykey instead of a defined value, so the Android text keeps skipping the extra styledText.Verification
platformFontFamily.spec.tscovers the rule as a pure function (Android dropsSystemfor*fontFamilykeys; iOS / web keep it; custom families, non-font keys and non-string values pass through), without redefiningPlatform.OS.style.spec.tsxcheckscreateThemedEntrykeepsSystemunder Jest's iOS platform. On master the Android case rendersSystem.yarn test --runInBand(75 suites, 1892 tests),turbo build components,yarn typecheck:all, lint (0 errors).Changeset:
@ui-kitten/componentspatch.