@amazon-devices/react-native-vector-icons library provides support on Vega for react-native-vector-icons. The library provides customizable vector icons ideal for embellishing buttons, logos, and navigation or tab bars that seamlessly integrate into your projects. Their versatility makes extension and styling effortless.
This library is system-deployed and available to React Native for Vega apps without a separate installation process. The library is deployed as an autolinking library, which your app links to at runtime. The library is guaranteed to be compatible only with the version of React Native for Vega for which it’s built.
When you uplevel your app’s version of React Native for Vega, consider the best practice of upleveling its library dependencies.
For more information about this library and its API, see the README.md in the GitHub repo.
Installation
-
Add the JavaScript library dependency in the package.json file:
-
Reinstall the dependencies using the
npm installcommand. -
Add your font files to
<app_package_root>/assets/fonts.
Upgrading
Upgrade the font files linked to your projects when you upgrade this package. If the automatic linking works for you, running it again should update the fonts. Otherwise, follow the steps outlined in the installation section.Examples
IconExplorer
Try the IconExplorer project in packages/icon-explorer in the GitHub react-native-vector-icons repo. There you can also search for any icon.
Basic example
A basic example of returning an icon:TabBar
The following example shows how to implement a TabBar. An example taken fromreact-navigation:
API reference
Icon component
Either use one of the icons that come with the library (the following example uses the icon from FontAwesome.js) or create your own custom font.Props
Use any Text property and the following:Methods
The following are static methods. | Method | Description | | —— | ———– | |getFontFamily | Returns the font family that is currently used to retrieve icons as text. Usage: const fontFamily = Icon.getFontFamily() | | getImageSource | Returns a promise that resolves to the source of a bitmap version of the icon for use with Image component. Usage: const source = await Icon.getImageSource(name, size, color) | | getImageSourceSync | Same as getImageSource but synchronous. Usage: const source = Icon.getImageSourceSync(name, size, color) | | getRawGlyphMap | Returns the raw glyph map of the icon set. Usage: const glyphMap = Icon.getRawGlyphMap() | | hasIcon | Checks if the name is valid in current icon set. Usage: const isNameValid = Icon.hasIcon(name)` |
Styling
Icon builds on top of the Text component, therefore most style properties work as expected.
Try these properties:
backgroundColorborderWidthborderColorborderRadiuspaddingmargincolorfontSize
Icon.Button component
A convenience component for creating buttons with an icon on the left side.Props
You can use anyText, TouchableHighlight, or TouchableWithoutFeedback property in addition to these:
Usage as PNG image/source object
Use with other components that rely on bitmap images rather than scalable vector icons. Takes the argumentsname, size, and color as described previously.
Icon.getImageSourceSync to avoid rendering glitches. Keep in mind that this method is blocking and might incur performance penalties. Subsequent calls use the cache.
Multistyle fonts
Thereact-native-vector-icons library supports multistyle fonts like FontAwesome 5. The usage is similar to the standard Icon component:
Methods
These methods are static, and those fromIcon are supported by multistyled fonts.
Components
Icon.Button is supported. Its usage is similar to Icon:
Custom fonts
createIconSet(glyphMap, fontFamily[, fontFile])
Returns your own custom font based on theglyphMap. The key is the icon name and the value is either a UTF-8 character or its character code. The name of the font is fontFamily, however this is not the name of the filename. Open the font in Font Book.app or similar to learn the name.
createIconSetFromFontello(config[, fontFamily[, fontFile]])
You can create a custom font based on a fontello config file. Don’t forget to import the font as described previously and place the config.json somewhere convenient in your project.createIconSetFromIcoMoon(config[, fontFamily[, fontFile]])
.json file that’s included in the .zip you’ve downloaded. Import the .ttf font file into your project, following the previous instructions.
createMultiStyleIconSet(styles [, options])
Animation
React Native comes with an animation library calledAnimated. To use it with an icon, create an animated component with this code: const AnimatedIcon = Animated.createAnimatedComponent(Icon).

