Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing custom icons into React Native 0.62

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:

  1. Created my icon set and converted it to fonts on https://icomoon.io
  2. Downloaded the zip file from IcoMoon and placed the ttf file into ./src/assets/fonts folder
  3. I then created react-native-config.js file and placed in the root. The code in this file is down below
  4. Under my components folder, I created CustomIcon.js -- see code below
  5. I also placed the selection.json file that was included in the zip file I downloaded from IcoMoon in the same folder as CustomIcon.js
  6. I then used the CustomIcon as shown below

So 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?

like image 600
Sam Avatar asked May 15 '20 17:05

Sam


People also ask

How do I use custom SVG icons in react-native?

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.

How do I use custom icons in react?

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.


Video Answer


1 Answers

There is a really good article which helped me with this problem.

Custom icon fonts with React Native

like image 53
Diyorbek Sadullaev Avatar answered Sep 21 '22 11:09

Diyorbek Sadullaev