Build for scale: Use custom fonts in React Native
Malik Chohra
React Native Mobile Engineer | Sharing Insights on Software Engineering | Digital Nomad Lifestyle | Passionate about Team Collaboration, processes and modern technology
Introduction
This series of build for scale: Is About the advanced way to use React native app.
I will talk about methods, best practices, how-to use guides, and advanced approaches on how to use the most used tools, and packages. Taking into account how to structure it in your app, how to architect the solution, and advanced approaches for a performant, secure, and scalable app.
This series is perfect for React Native developers of all levels who want to take their skills to the next level and build apps that stand the test of time. Whether you’re a seasoned professional or just starting, you’ll find invaluable knowledge and practical guidance to transform your React Native development journeyI explained in the previous article how to optimise
In this small tech Article, I will guide you to use custom fonts in React Native, with an example of mapping those fonts for RTL and Internalizations.
Choose Your?Font:
Place the Font File:
Linking Assets?:
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./src/assets/fonts/'], // stays the same
};
npx react-native-asset
For React Native Version< 0.69
npx react-native link
link command will links fonts in Info.plst for IOS and creates fonts directory (android/app/src/main/assets/fonts) for Android, where copies your fonts
The assets in the assets folder (including your font files) are automatically included in the native project during build time.
领英推荐
How to use the?fonts:
In your Typography folder, add the following:
We use it in StyledText in the following way:
Conclusion
There are different issues when using custom fonts
Mismatched Font Family?Names:
Unsupported Font?Formats:
Performance Impact:
#reactnative #react #typescript #mobiledevelopment #engineering #patterns #bestpractices #memoryleak #performance #scaleApp #fastApp #userexperience