react-native: 0.60.4,
react: 16.8.6,
npm: 6.10.1
XCode: 10.2.1
AndroidStudio: 3.4.1
I created a project using
npx react-native init awesomeApp --template typescript
I have put my assets in the
assets/fonts/<Bunch of .ttf files>
My Directory Structure
awesomeApp
|
+--android
+--ios
+--assets
| |
| +---fonts
| |
| +-- ProximaNova-Bold.ttf
+--react-native-config.js
then I ran
react-native link
Nothing happends, XCode not showing any added Resource neither the android, and when I'm running react-native run-ios
showing error that the font is not found.
My react-native-config.js
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts']
};
I have also tried
yarn react-native link
and npx react-native link
If you did not use the react-native link command but still received the error, it's likely that one of your dependencies is not suitable for autolinking. If that is the case, you can try using [patch-package](https://www.npmjs.com/package/patch-package) to fix it on your own.
Custom fonts can be added into React Native project (0.60+) with the following steps. 1. Get the font files needed for the project The font files should be either in .ttf or .otf format. The font files can be obtained from Google fonts. Create a folder named fonts under the assets directory and place the font files in it.
So react-native link ./assets/fonts is not a valid command, but it should work. Do remember you need your fonts dir specified in package.json as per Hamed's answer. This error has no effect on linking assets.
So if you ever just want to link your fonts you can do that by linking some specific library along with it. If you just want to link your assets folder, try react-native link "package-that-does-not-exist", it will still link your assets without linking anything else.
If you just want to link your assets folder, try react-native link "package-that-does-not-exist", it will still link your assets without linking anything else. Show activity on this post. There is a suitable package called react-native-assets, which links & unlinks only the assets.
Well, finally, I linked my fonts,
I just renamed my file react-native-config.js
to react-native.config.js
and it worked.
I don't know if this is the right way, I just tried and it worked, for me at least.
Here is the complete walkthrough for linking custom fonts.
my react-native.config.js
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/'],
};
and logs:
info Linking assets to ios project
info Linking assets to android project
success Assets have been successfully linked to your project
but My mistake was:
Wrong way:
fontFamily: BYekan
Right way:
fontFamily: 'BYekan'
just put font name in ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With