Glyph to png conversion for react native vector icons
npm install @react-native-vector-icons/get-image!Vector Icons for React Native
 
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 visit
- 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
Should you find this library beneficial, kindly contemplate the option of
sponsoring.
RNVI comes with the following supported icons. You can search NPM for third party icons.
- AntDesign from Ant Group (v4.4.2 with _449_ icons)
- Feather created by Cole Bemis & Contributors (v4.29.2 featuring _287_ icons)
- FontAwesome designed by Fonticons, Inc. (v7.1.0 featuring _2,806_ free and _75,767_ pro icons)
- Foundation by ZURB, Inc. (v3.0 with _283_ icons)
- Ionicons crafted by Ionic (v8.0.9 containing _1,357_ icons)
- MaterialDesignIcons from MaterialDesignIcons.com (v7.4.47 including _7448_ icons)
- Octicons designed by GitHub, Inc. (v19.19.0 with _339_ icons)
- Lucide designed by Lucide, (v0.548.0 with _1,639_ icons)
- Entypo by Daniel Bruce (v1.0.1 with _411_ icons)
- EvilIcons designed by Alexander Madyankin & Roman Shamin (v1.10.1 with _70_ icons)
- FontAwesome 4 by Fonticons, Inc. (v4.7.0 containing _785_ icons)
- FontAwesome 5 from Fonticons, Inc. (v5.15.4 offering _1611_ free and _7869_ pro icons)
- FontAwesome 6 designed by Fonticons, Inc. (v6.7.2 featuring _2060_ free and _52663_ 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)
See MIGRATION.md if you are migrating from react-native-vector-icons to the package-per-icon-set approach or between major versions.
1. Install the packages for the icons you want to use
``sh`
npm install @react-native-vector-icons/fontawesome6 @react-native-vector-icons/evil-icons
1. Depending on the platform you're targeting (iOS/Android/Windows), follow the appropriate setup instructions below.
1. If you are using one of the following fonts, refer to their guides for further instructions
- FontAwesome 6
- FontAwesome 6 Pro
- FontAwesome 5
- FontAwesome 5 Pro
- Fontello
- Icomoon
Refer to the guide for Expo, React Native or Web for further instructions.
For fonts like fontawesome6-pro, fontello and icomoon where you provide the fonts the default location for the font files is rnvi-fonts in the same directory as your package.json. This can be customized by setting the fontDir property in your package.json file.
`json`
{
"reactNativeVectorIcons": {
"fontDir": "src/rnvi-fonts"
}
}
ComponentYou can either use one of the bundled icons above or roll your own custom font.
`js
import { FontAwesome } from "@react-native-vector-icons/fontawesome";
`
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_ |
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:
- backgroundColorborderWidth
- borderColor
- borderRadius
- padding
- margin
- color
- fontSize
-
By combining some of these you can create for example :
Some fonts today use multiple styles, FontAwesome 6 for example, which is supported by this library. The usage is pretty much the same as the standard Icon component:
`jsx
import { FontAwesome5 } from "@react-native-vector-icons/fontawesome5";
`
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.
You need to install @react-native-vector-icons/get-image to use this feature.
`jsx
const source = Icon.getImageSourceSync('user', 20, 'red');
return
);
`
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.
All static methods from Icon are 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) |
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. ThisglyphMap
returns your own custom font based on the where the key is the iconpostScriptName
name and the value is either a UTF-8 character or its character code. is the name of the postscript font. Open the font in fontFileName
Font Book.app or similar to learn the name. Also pass the argument for Android support.
`js
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.
});
If you aren't using dynamic font loading you need to make sure your font is copied into your bundle.
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 loading is supported on all platforms if you use Expo (Expo Go or a development client). 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: use createIconSet as seen in custom fonts paragraph to obtain a icon font family with dynamic font loading enabled. See any of the free font packages for reference.
By default, dynamic loading is enabled if you run Expo SDK >= 52. 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.
Try the IconExplorer project in Examples/IconExplorer folder, there you can also search for any icon.
`js
import { IonIcons } from "@react-native-vector-icons/ionicons";
const ExampleView = () => (
);
`
`js
import { Text } from "react-native";
import { IonIcons } from "@react-native-vector-icons/ionicons";
const ExampleView = (props) => (
Lorem
);
`
When running tests with jest you will need to mock out the native code loading to prevent errors.
In jest.config.js add
`js`
// Mock out font loading
moduleNameMapper: {
'\\.(ttf)$': '
}
Create __mocks__/file-mock.js:
`js`
module.exports = {};
Create __mocks__/@react-native-vector-icons/common.js:
`js``
// Mock the entire common library so there are no native module loading errors
module.exports = {
createIconSet: () => "icon",
};
This project is licenced under the MIT License.
Any bundled fonts are copyright to their respective authors and mostly under MIT or SIL OFL.