Reputation: 30330
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?
Upvotes: 10
Views: 10861
Reputation: 477
There is a really good article which helped me with this problem.
Custom icon fonts with React Native
Upvotes: 2
Reputation: 1228
There is always issue with custom icons. When I personally bump into such condition I do these:
Rename the
react-native-config.js
toreact-native.config.js
Re-run the app by restarting metro
Make sure I have correct path to my assets in
react-native.config.js
react-native link
and restart. It copies your assets to corresponding ios and android folders
If neither do not help I copy the assets manually to folder: Project/android/app/src/main/assets/fonts
Upvotes: 1