How to Add React Native Vector Icons and Custom Fonts

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the Building React Native Apps for Mac course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Building React Native Apps for Mac, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Building React Native Apps for Mac

In this lesson, we will be adding vector icons and custom fonts to our application. So far, we have gotten along by using all the basic components from React Native, but React Native itself doesn't come with any icon pack. Now the reason we're doing this in the Mac section of the course is because it 's not quite as straightforward. The platform or the support from the library that we're going to use is not the same as on iOS. So there are some details that we need to take care just because we're on the Mac. So there is one easy way to add the icons, which is just linking the fonts folder from the package right into your application. However, that comes with the downside, which means we won't be able to add any custom fonts afterwards. So we're going to take a different route and we're going to manually add the fonts into our application. So we're going to start by adding the package that we're going to use. It's called React Native Vector icons. And we are also going to take this opportunity and add the types for it. Great. So now that we have that, this is going to be the first time that we're going to open Xcode on our own and manually modify the structure of the project. So I'm just going to open Xcode. And from Xcode, I am just going to open a project or a file. I'm going to go to my developer folder. I'm going to go into the project, macOS, and the XC workspace is the file that I'm looking for. I'm just going to open that. Xcode is going to load. And now we need to create some folders first. So I'm going to go going to open my terminal. I'm going to go into the macOS folder. Now here you can see I have a bunch of folders. And I'm going to go inside the macOS one. Once in there, I'm going to create a folder and I'm going to call it fonts. Now we need to take care or we need to grab the font files from the vector icons package and put it into this folder. So I'm just going to do it via command line, but you can do it whatever way you want. So if I'm already in this folder, I can just use the following command. And let me just check. Yes. Okay. So I can just go no modules. And react. This is probably not working the way I expected to be. Okay, it doesn't matter. I'm just going to navigate to the folder myself. And I'm going to go into the fonts folder and I'm just going to open that. And here you can see are all the icon fonts. So I'm just going to select all of them, then going to go back into the macOS folder. Going to find the folder that we created and I'm just going to make a copy of them in there. Great. Now with the fonts in place, I'm going to go back into Xcode and I'm going to take a look at the explorer. So you will see here that even though we created the folder itself, it's not appearing on our explorer. Because Xcode doesn't directly read the directory, you actually need to register each file within the project structure. So in order to do this, I'm just going to right click on the macOS folder and I 'm going to say add files to building apps. And I'm going to find my font folder. I'm going to make sure that create folder references is selected. I'm going to add it. And here you can see now it has picked up all of our fonts. We still need to take care of one more value, which is on the info playlist. This is just a file that contains some configuration specific for the native platform. And instead of here, I'm going to go for application fonts resource path. And I'm going to pass the name fonts. So basically what this is going to do is going to add all of the files within the fonts directory into the app itself into the bundle app. And in order to test this, I'm not going to run it from the console. I'm just going to run it from the scode just for you to check out how this works. You have to select the macOS app and you have to select it on the my Mac. And we can hit run and you will see that our application has started. So with my application in here, I'm going to go back into my books container. And I'm going to import the icons, right? So I imported from my package and this package in particular because it has many different fonts from different sources, you have to specify the sub package where you want to import the icon component. So now that I have the icon component in there, I am going to change the small change within my view container for my book title. I'm going to change the direction. You have flex. And I'm going to insert an icon in there. So if I save it, perfect. Right? So if you want to use any other icons, you can go into, well, you kind of have to search for each package, right? Because there is many of them, but you can look at the names, right? And you can use a lot of them within your app. Great. So let's get out of the way. And right. So the final step is adding custom fonts. But basically it's going to be the same process that we already did, right? We already have our fonts folder within our app. Here, we already have our fonts folder. So you're just going to take whatever font you want to add, put it in here. You don't have to do anything else on Xcode. It's going to be linked. And afterwards, you can just use it as a font family property whenever you pass a style into your application.