-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Android fonts linking process #52
base: master
Are you sure you want to change the base?
Improve Android fonts linking process #52
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems overall good and almost ready for merge!
- My comments are mainly nitpicks, but are easy to fix.
- Resolve conflict with
master
by rebase, since PR's are usually squash merged tomaster
, I suggest when the conflict comes up to discard youryarn.lock
andpackage.json
changes and just reinstall everything using yarn. - The main issue is that I want the transition to the new version (probably
3.0.0
) to be seemless, and for that we need to unlink and link again the font assets, try to add amigration
that does that.- currently each migration just takes old manifests and returns new ones if something has changed in it's structure, but in this PR you don't need to change the structure, just link and unlink the fonts, maybe add a way to do that in the newly created migration for this PR
@unimonkiez Thanks for your review! About the migration, even if I implement it won't be 100% seamless as it would require changes in the application as well, specifically how the developer use |
Sounds excellent ! |
… when such migration occur
2c1c42f
to
a902630
Compare
@unimonkiez I updated the PR with the following changes:
|
Hi @unimonkiez , did you have a chance to take a look at the latest changes on this PR? Thanks! |
Hi @unimonkiez, just bringing this PR to your attention again, I appreciate any feedback or action you could take. Thanks! |
@unimonkiez thanks for your reviews of this pull request so far. We'd love to help push this feature forward in whatever way we can 🙂 |
Thanks for your work @fabioh8010 and @unimonkiez If anyone wants to use it now:
|
This PR aims to improve the whole Android fonts linking process.
Problem
Currently, during Android linking, font assets are copied to Android asset's folder and then can be used in the application. The problem is that in RN Android has a different logic to manage fonts related to iOS, requiring the developer to rely on the font file's name to be able to use the font properly in the application.
To give an example, let's say I added Lato font to my project and linked the files in both Android and iOS platforms. These are the Lato font files:
For iOS, I can simply use a combination of
fontFamily
,fontWeight
andfontStyle
styles to select the desired font:For Android, this approach won't work and you have to rely on the font's name in order to select the desired font.
Developers end up having to use different approaches in order to custom fonts work properly for both platforms.
Solution
This PR solves the stated problem by changing the Android linking process to do the steps described in this guide automatically. In Android, fonts are now going to be managed by using XML Fonts to handle all font's variants.
During font assets copying process, here is the following logic:
res/font/
folder and normalize their names.ReactFontManager
's import toMainApplication.java
file if it isn't declared yet.onCreate()
to load the custom font on Android.During font assets cleaning process, here is the following logic:
res/font
folder that needs to be deleted.MainApplication.java
.ReactFontManager
inMainApplication.java
, remove the import as well.