I'm trying to import and use my own custom icons in my React Native 0.62.2
app.
I followed the steps outlined here https://github.com/oblador/react-native-vector-icons#custom-fonts but so far the icons are not showing up.
Here are the steps I followed:
IcoMoon
and placed the ttf
file into ./src/assets/fonts
folderreact-native-config.js
file and placed in the root. The code in this file is down belowCustomIcon.js
-- see code belowselection.json
file that was included in the zip
file I downloaded from IcoMoon
in the same folder as CustomIcon.js
CustomIcon
as shown belowSo here what the codes look like:
The react-native-config.js
file looks like this:
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./src/assets/fonts/']
};
The CustomIcon.js
file looks like this:
import { createIconSetFromIcoMoon } from 'react-native-vector-icons';
import icoMoonConfig from './selection.json';
export default createIconSetFromIcoMoon(icoMoonConfig, 'StreamLine', '../../../assets/fonts/streamline-icon-set-1.ttf');
And here's how I use the icon:
import CustomIcon from '../common_components/fonts/CustomIcon';
<CustomIcon name="home-outline" />
When I run the app in Android Emulator
, I see the missing icon symbol i.e. a box with an X in it.
Any idea what the issue is here?
Remove the current set (if there is one) and create a new empty set and give your preferred name (remember to give the same name everywhere). Drag and drop your SVG files onto the tool. Select the files which you want to export. Select all if you want to export all the icons.
First we have to create a custom icon set. (it is recommended that you rename everything now, before downloading and make sure you use the same name everywhere). Drag and drop your SVG files onto the website. Highlight (select) the files that you want to export. Select all if you want to export all the icons.
There is a really good article which helped me with this problem.
Custom icon fonts with React Native
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