Skip to content
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

How to access fonts from res/font folder? #15170

Closed
rajsuvariya opened this issue Jul 24, 2017 · 7 comments
Closed

How to access fonts from res/font folder? #15170

rajsuvariya opened this issue Jul 24, 2017 · 7 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@rajsuvariya
Copy link
Contributor

As to provide custom fonts in react native I need to keep my fonts at assets/fonts. But as per the new version of support library of android I have to keep fonts in res/font in order to apply it directly in xml. So I cannot keep my fonts at assets/fonts. Please update this in React native so that the res/font are directly accessible

@hey99xx
Copy link

hey99xx commented Jul 24, 2017

You can certainly load the font yourself and inject into ReactFontManager.

Also I don't think having res/font font files and loading from xml is an absolute requirement. Most react-native apps simply don't deal with xml created views, so loading from assets is fine for most. I'd imagine this will not be a highly-requested feature, but it'd a nice addition nonetheless.

This method Resources#getFont(int) is only introduced in SDK level 26 though, but RN currently is compiled against SDK level 23. So there would be some significant work before introducing an API for this. It'd be probably easier to have a custom native module in your own app to load the font file.

@hey99xx
Copy link

hey99xx commented Jul 24, 2017

If someone wants to add label to the question (I can't) -- choose "Android" and "Feature Request".

@hramos hramos added the Android label Jul 24, 2017
@hramos
Copy link
Contributor

hramos commented Jul 24, 2017

Thanks for opening the issue! As it happens, we're using GitHub to track bugs in React Native. If you'd like to submit this as a feature request, please go ahead and create an entry on Canny. It has a voting system and if the feature gets a good amount of votes, it will have a greater chance of being implemented by the community. Closing this now, thanks for understanding!

@hramos hramos closed this as completed Jul 24, 2017
@rajsuvariya
Copy link
Contributor Author

@hey99xx Yes, for applying fonts directly in xml using support library 26 we need to keep it inside res folder. Anyway I added feature request on Canny as asked by @hramos

@akoufa
Copy link

akoufa commented Feb 9, 2018

Hello. I am reopening this issue/ feature request again as the link for Canny does not seem to work. I tried to put my fonts in the Android res folder but that does not seem to work with React Native 0.51 . Unfortunately I must put my custom fonts both in the res folder and in the assets/fonts folder so I can use them in React Native and Android ( native) respectively. Is there any solution for this I might have overseen?

@hey99xx
Copy link

hey99xx commented Feb 9, 2018

Correct link to Canny https://react-native.canny.io/feature-requests

What's the point of putting your custom fonts in res folder, why not just keep them in assets? Android's support for assets folder did not disappear just because now they made res folder the suggested location. If you want, create the Typeface from res yourself, and inject into RN via https://github.com/facebook/react-native/blob/0.50-stable/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java#L83

@akoufa
Copy link

akoufa commented Feb 9, 2018

There would be no point and you would be right if I did not have to use the same fonts in the Android Java/XML code too. Now I am obligated to add the fonts two times, one in the assets/fonts folder and one in the res/font folder. Or I have to use your suggestion and add them programmatically. Thank you for the correct Canny link.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants