-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Description
For Discussion
Android SDK 26 introduced easy way to support custom fonts, where users define font family using XML and use it with ResourcesCompat.getFont(context, R.font.myfont). Read https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml
Current React Native support for custom fonts on Android implemented in ReactFontManager and CustomStyleSpan, and it's hard to use font weights other than bold and regular (normal), like medium, light etc. To use custom font weights on Android, I have to specify font file name without extension in fontFamily of style, which breaks iOS apps. Therefore, I check the platform in JS to support both Android and iOS, and set fontFamily and fontWeight accordingly.
Adding support for Android Way seemed trivial with fallback to old way.
- check if font resource is exists
- if exists, get resource id and get typeface using ResourcesCompat.getFont(context, )
- else fallback to old way (ReactFontManager)
But, font styling of Text in Android implemented in ReactBaseTextShadowNode, which have no access to context. So, I think support custom fonts the Android Way will require refactoring of Text and decide if RN will support the OLD WAY.
Please consider this for FabricUIManager