react-native-vector-icons
Customizable Icons for React Native with support for image source and full styling.
Top Related Projects
The iconic SVG, font, and CSS toolkit
Cross-Platform React Native UI Toolkit
A pack of more than 480 beautifully crafted Open Source icons. SVG, Sketch, Web Font and Animations support.
Bringing Material Design to React Native
Quick Overview
React Native Vector Icons is a popular library that provides customizable icons for React Native applications. It offers a wide range of icon sets, including Material Design icons, FontAwesome, and many others, allowing developers to easily integrate and style icons in their mobile apps.
Pros
- Large selection of icon sets available
- Easy integration with React Native projects
- Customizable icon styles and sizes
- Regular updates and active community support
Cons
- Can increase app bundle size if not optimized
- Some icon sets may require additional setup or licensing considerations
- Occasional compatibility issues with certain React Native versions
- Limited support for custom SVG icons
Code Examples
- Basic usage of an icon:
import Icon from 'react-native-vector-icons/FontAwesome';
const MyComponent = () => (
<Icon name="rocket" size={30} color="#900" />
);
- Creating a custom icon button:
import Icon from 'react-native-vector-icons/Ionicons';
import { TouchableOpacity } from 'react-native';
const IconButton = ({ onPress }) => (
<TouchableOpacity onPress={onPress}>
<Icon name="ios-add-circle" size={24} color="#007AFF" />
</TouchableOpacity>
);
- Using icons in a tab navigator:
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import Icon from 'react-native-vector-icons/MaterialIcons';
const Tab = createBottomTabNavigator();
const TabNavigator = () => (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === 'Home') {
iconName = focused ? 'home' : 'home-outline';
} else if (route.name === 'Settings') {
iconName = focused ? 'settings' : 'settings-outline';
}
return <Icon name={iconName} size={size} color={color} />;
},
})}
>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
Getting Started
-
Install the library:
npm install react-native-vector-icons
-
Link the library (for React Native < 0.60):
react-native link react-native-vector-icons
-
For iOS, add the following to your
Info.plist
:<key>UIAppFonts</key> <array> <string>AntDesign.ttf</string> <string>Entypo.ttf</string> <string>EvilIcons.ttf</string> <string>Feather.ttf</string> <string>FontAwesome.ttf</string> <!-- Add other icon fonts as needed --> </array>
-
For Android, add the following to your
android/app/build.gradle
:apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
-
Start using icons in your components:
import Icon from 'react-native-vector-icons/FontAwesome'; const MyComponent = () => ( <Icon name="user" size={30} color="#900" /> );
Competitor Comparisons
The iconic SVG, font, and CSS toolkit
Pros of Font-Awesome
- Extensive icon library with over 7,000 icons
- Regular updates and additions to the icon set
- Widely recognized and used across various web projects
Cons of Font-Awesome
- Not specifically designed for React Native, may require additional setup
- Larger file size due to the comprehensive icon set
- Limited customization options compared to React Native Vector Icons
Code Comparison
React Native Vector Icons:
import Icon from 'react-native-vector-icons/FontAwesome';
<Icon name="rocket" size={30} color="#900" />
Font-Awesome (with react-native-fontawesome):
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
import { faRocket } from '@fortawesome/free-solid-svg-icons';
<FontAwesomeIcon icon={faRocket} size={30} color="#900" />
Summary
React Native Vector Icons is specifically designed for React Native projects, offering easier integration and better performance. It provides a wide range of icon sets and allows for easy customization.
Font-Awesome, while not tailored for React Native, offers a vast library of icons and is widely recognized. It may require additional setup but provides regular updates and a comprehensive set of icons suitable for various projects.
The choice between the two depends on the specific needs of your React Native project, considering factors such as ease of integration, performance, and the range of icons required.
Cross-Platform React Native UI Toolkit
Pros of React Native Elements
- Comprehensive UI toolkit with pre-built components
- Consistent design language across components
- Customizable theming system for easy styling
Cons of React Native Elements
- Larger package size due to extensive component library
- Steeper learning curve for customizing complex components
- May include unnecessary components, increasing app bundle size
Code Comparison
React Native Elements:
import { Button, Icon } from 'react-native-elements';
<Button
icon={<Icon name="arrow-right" size={15} color="white" />}
title="Button with Icon"
/>
React Native Vector Icons:
import Icon from 'react-native-vector-icons/FontAwesome';
<Icon.Button name="facebook" backgroundColor="#3b5998">
Login with Facebook
</Icon.Button>
React Native Vector Icons focuses primarily on providing a wide range of icon sets, while React Native Elements offers a more comprehensive UI toolkit. The former is lightweight and specialized for icons, making it ideal for projects that only need icon support. React Native Elements, on the other hand, provides a full suite of pre-styled components, which can speed up development but may introduce unnecessary overhead for simpler projects.
When choosing between the two, consider your project's specific needs, desired customization level, and performance requirements. React Native Vector Icons is best for icon-focused needs, while React Native Elements suits projects requiring a complete UI component library.
A pack of more than 480 beautifully crafted Open Source icons. SVG, Sketch, Web Font and Animations support.
Pros of eva-icons
- Offers a comprehensive design system with consistent styling across icons
- Provides both SVG and web font versions of icons
- Includes a user-friendly web application for icon browsing and customization
Cons of eva-icons
- Limited to a specific design style, which may not suit all projects
- Fewer icon options compared to react-native-vector-icons
- Requires additional setup for integration with React Native projects
Code Comparison
react-native-vector-icons:
import Icon from 'react-native-vector-icons/FontAwesome';
<Icon name="rocket" size={30} color="#900" />
eva-icons (with react-native-svg):
import { Icon } from 'react-native-eva-icons';
<Icon name="star" width={30} height={30} fill="#900" />
Summary
react-native-vector-icons is a popular choice for React Native projects, offering a wide variety of icon sets and easy integration. It's particularly well-suited for mobile app development.
eva-icons, on the other hand, provides a cohesive design system with both SVG and web font options. It's more versatile for web projects but requires additional setup for React Native integration.
The choice between the two depends on project requirements, design preferences, and the target platform. react-native-vector-icons is more straightforward for React Native development, while eva-icons offers a comprehensive design system that may be beneficial for projects requiring consistent styling across multiple platforms.
Bringing Material Design to React Native
Pros of react-native-material-kit
- Provides a comprehensive set of Material Design components
- Offers a more cohesive design system for Material Design-based apps
- Includes both UI components and styling utilities
Cons of react-native-material-kit
- Less frequently updated compared to react-native-vector-icons
- Focused solely on Material Design, limiting flexibility for other design systems
- Steeper learning curve due to more complex components
Code Comparison
react-native-vector-icons:
import Icon from 'react-native-vector-icons/MaterialIcons';
<Icon name="menu" size={24} color="black" />
react-native-material-kit:
import { MKButton } from 'react-native-material-kit';
<MKButton
backgroundColor={MKColor.Teal}
shadowRadius={2}
shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={() => console.log('Hi!')}
>
<Text pointerEvents="none" style={{color: 'white', fontWeight: 'bold'}}>
BUTTON
</Text>
</MKButton>
react-native-vector-icons focuses primarily on providing a wide range of icon sets, while react-native-material-kit offers a more comprehensive Material Design implementation with various UI components. The choice between the two depends on whether you need just icons or a full Material Design component library for your React Native project.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
React Native Vector Icons
Elevate your React Native applications with the power of customizable vector icons. Ideal for embellishing buttons, logos, and navigation or tab bars, these icons seamlessly integrate into your projects. Their versatility makes extension and styling effortless.
For the integration of .svg
files natively, you can explore react-native-vector-image
.
[!TIP] If you are still using the old single package
react-native-vector-icons
please visit https://github.com/oblador/react-native-vector-icons/tree/10.x
Table of Contents
- Sponsorship
- Available Icon Sets
- Installation
- Setup
- Icon Component
- Usage as PNG Image/Source Object
- Multi-Style Fonts
- Custom Fonts
- Animation
- Dynamic icon font loading
- Usage Examples
- Changelog
- License
Sponsorship
Should you find this library beneficial, kindly contemplate the option of sponsoring.
Available Icon Sets
RNVI comes with the following supported icons. You can search NPM for third party icons.
Actively maintained
AntDesign
from Ant Group (v4.4.2 with 449 icons)Feather
created by Cole Bemis & Contributors (v4.29.2 featuring 287 icons)FontAwesome 6
designed by Fonticons, Inc. (v6.7.1 featuring 2060 free and 52663 pro icons)Foundation
by ZURB, Inc. (v3.0 with 283 icons)Ionicons
crafted by Ionic (v7.4.0 containing 1356 icons)MaterialDesignIcons
from MaterialDesignIcons.com (v7.4.47 including 7448 icons)Octicons
designed by GitHub, Inc. (v19.12.0 with 331 icons)
No longer maintained upstream
Entypo
by Daniel Bruce (v1.0.1 with 411 icons)EvilIcons
designed by Alexander Madyankin & Roman Shamin (v1.10.1 with 70 icons)FontAwesome
by Fonticons, Inc. (v4.7.0 containing 785 icons)FontAwesome 5
from Fonticons, Inc. (v5.15.4 offering 1611 free and 7869 pro icons)Fontisto
created by Kenan GündoÄan (v3.0.4 featuring 617 icons)MaterialIcons
by Google, Inc. (v4.0.0 featuring 2234 icons)SimpleLineIcons
crafted by Sabbir & Contributors (v2.5.5 with 189 icons)Zocial
by Sam Collins (v1.1.1 with 100 icons)
Migration
See MIGRATION.md if you are migrating from react-native-vector-icons
to the package-per-icon-set approach.
Installation
- Install the common package
npm install --save @react-native-vector-icons/common
- Install the packages for the icons you want use
npm install --save @react-native-vector-icons/fontawesome6 @react-native-vector-icons/evil-icons
- Depending on the platform you're targeting (iOS/Android/Windows), follow the appropriate setup instructions below.
- If you are using one of the following fonts refer to their guides for further instructions
Setup
Please refer to the guide for Expo, React Native or Web for further instructions.
Icon
Component
You can either use one of the bundled icons above or roll your own custom font.
import Icon from '@react-native-vector-icons/fontawesome';
const myIcon = <Icon name="rocket" size={30} color="#900" />;
Props
Any Text props and the following:
Prop | Description | Default |
---|---|---|
size | Size of the icon, can also be passed as fontSize in the style object. | 12 |
name | What icon to show, see Icon Explorer app or one of the links above. | None |
color | Color of the icon. | Inherited |
Static Methods
Prop | Description |
---|---|
getImageSource | Returns a promise that resolving to the source of a bitmap version of the icon for use with Image component et al. Usage: const source = await Icon.getImageSource(name, size, color) |
getImageSourceSync | Same as getImageSource but synchronous. Usage: const source = Icon.getImageSourceSync(name, size, color) |
Styling
Since Icon
builds on top of the Text
component, most style properties will work as expected, you might find it useful to play around with these:
backgroundColor
borderWidth
borderColor
borderRadius
padding
margin
color
fontSize
By combining some of these you can create for example :
Usage as PNG Image/Source Object
Convenient way to plug this in into other components that rely on bitmap images rather than scalable vector icons. Takes the arguments name
, size
and color
as described above.
const source = Icon.getImageSourceSync('user', 20, 'red');
return <Image source={source} />;
);
Alternatively you may use the async method Icon.getImageSource
.
Keep in mind that Icon.getImageSourceSync
is blocking and might incur performance penalties. Subsequent calls will use cache however.
Multi-Style Fonts
Some fonts today use multiple styles, FontAwesome 5 for example, which is supported by this library. The usage is pretty much the same as the standard Icon
component:
import Icon from '@react-native-vector-icons/fontawesome5';
const myIcon1 = <Icon name="comments" size={30} color="#900" />; // Defaults to solid
const myIcon2 = <Icon name="comments" size={30} color="#900" iconType="solid" />;
const myIcon3 = <Icon name="comments" size={30} color="#900" iconType="light" />; // Only in FA5 Pro
Static methods
All static methods from Icon
is supported by multi-styled fonts.
Prop | Description |
---|---|
getImageSource | Returns a promise that resolving to the source of a bitmap version of the icon for use with Image component et al. Usage: const source = await Icon.getImageSource(name, size, color) |
getImageSourceSync | Same as getImageSource but synchronous. Usage: const source = Icon.getImageSourceSync(name, size, color) |
Custom Fonts
The best approach is to use our icon generator to create your own icon package.
See CREATE_FONT_PACKAGE.md to learn how to create your own font packages.
You can also use createIconSet()
directly in your project. This
returns your own custom font based on the glyphMap
where the key is the icon
name and the value is either a UTF-8 character or it's character code.
postScriptName
is the name of the postscript font. Open the font in https://fontdrop.info/,
Font Book.app or similar to learn the name. Also pass the fontFileName
argument for Android support.
import { createIconSet } from '@react-native-vector-icons/common';
const glyphMap = { 'icon-name': 1234, test: 'â' };
// use createIconSet() with object parameter
// or use positional parameters for compatibility with version <= 10: `createIconSet(glyphMap, fontFamily[, fontFile])`
const Icon = createIconSet(glyphMap, {
postScriptName: 'FontName',
fontFileName: 'font-name.ttf',
fontSource: require('../fonts/font-name.ttf') // optional, for dynamic loading. Can also be a local file uri.
})
You should place the font ttf file into rnvi-fonts
. You can customise this location by adding the following snippet to your package.json
{
"reactNativeVectorIcons": {
"fontDir": "src/assets/fonts"
}
}
Animation
React Native comes with an amazing animation library called
Animated
. To use it with an
icon, simply create an animated component with this line: const AnimatedIcon = Animated.createAnimatedComponent(Icon)
. You can also use the higher level
animation library
react-native-animatable.
Dynamic icon font loading
At the moment, dynamic loading is supported on native platforms (not on web) only if you use Expo. In the future, it should become available for all React Native projects via React Native core.
Fonts can be available in an app statically (since build time) or loaded dynamically at runtime. The latter can be useful e.g. for apps that use over-the-air updates and want to load new fonts with an update, or when you need to use a font from a remote location.
Dynamic loading in react-native-vector-icons is currently limited to those fonts that are bundled within the provided packages: it doesn't support Pro fonts (such as FontAwesome 5 Pro). However, loading of custom fonts is not difficult to implement: see any of the free font packages for reference.
By default, dynamic loading is enabled if supported by the version of Expo that you're using. It doesn't change the way you work with the package: If rendering an icon requires a font that is not known to the app, it will be loaded automatically and icon will render as expected.
@react-native-vector-icons/common
exports several functions which you can use to control dynamic loading:
isDynamicLoadingEnabled
: Returns whether dynamic loading is enabled.isDynamicLoadingSupported
: Returns whether dynamic loading is supported by your runtime (checks that necessary Expo features are present).setDynamicLoadingEnabled
: Enables or disables dynamic loading.setDynamicLoadingErrorCallback
: Sets a callback that is called (in the unlikely case) when an error occurs during dynamic loading. An example of when an error might happen is loading a misconfigured OTA update which doesn't include a necessary font file.
Usage Examples
Icon Explorer
Try the IconExplorer
project in Examples/IconExplorer
folder, there you can also search for any icon.
Basic Example
import Icon from '@react-native-vector-icons/ionicons';
function ExampleView(props) {
return <Icon name="ios-person" size={30} color="#4F8EF7" />;
}
Inline Icons
import { Text } from 'react-native';
import Icon from '@react-native-vector-icons/ionicons';
function ExampleView(props) {
return (
<Text>
Lorem <Icon name="ios-book" color="#4F8EF7" /> Ipsum
</Text>
);
}
Changelog
License
This project is licenced under the MIT License.
Any bundled fonts are copyright to their respective authors and mostly under MIT or SIL OFL.
Top Related Projects
The iconic SVG, font, and CSS toolkit
Cross-Platform React Native UI Toolkit
A pack of more than 480 beautifully crafted Open Source icons. SVG, Sketch, Web Font and Animations support.
Bringing Material Design to React Native
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot