
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
react-native-vector-icons
Advanced tools
The react-native-vector-icons package provides a set of customizable icons for React Native applications. It includes a variety of icon sets and allows for easy integration and customization of icons in your app.
Basic Icon Usage
This feature allows you to use icons from various icon sets like FontAwesome. You can specify the icon name, size, and color.
import Icon from 'react-native-vector-icons/FontAwesome';
const MyComponent = () => (
<Icon name="rocket" size={30} color="#900" />
);
Icon Button
You can use icons as buttons by wrapping them in a TouchableOpacity component. This makes the icon interactive.
import Icon from 'react-native-vector-icons/FontAwesome';
import { TouchableOpacity } from 'react-native';
const MyComponent = () => (
<TouchableOpacity>
<Icon name="rocket" size={30} color="#900" />
</TouchableOpacity>
);
Custom Icon Fonts
This feature allows you to create custom icon sets from Fontello or other similar services. You can then use these custom icons in your app.
import { createIconSetFromFontello } from 'react-native-vector-icons';
import fontelloConfig from './config.json';
const Icon = createIconSetFromFontello(fontelloConfig);
const MyComponent = () => (
<Icon name="custom-icon" size={30} color="#900" />
);
react-native-elements is a UI toolkit for React Native that includes a set of customizable components, including icons. It uses react-native-vector-icons under the hood but provides a more comprehensive set of UI components.
react-native-paper is a library that provides Material Design components for React Native. It includes an IconButton component that allows you to use icons from various icon sets, similar to react-native-vector-icons.
Choose from 2800 icons or use your own.
100% JavaScript = easy to extend, style and integrate into your project.
$ npm install react-native-vector-icons --save
If you want to use any of the bundled icons, you need to add the icon fonts to your XCode project. Just follow these steps:
node_modules/react-native-vector-icons
and select the folder Fonts
(or just the ones you want).Info.plist
and add a property called Fonts provided by application (if you haven't added one already) and type in the files you just added. It will look something like this:Note: you need to recompile your project after adding new fonts.
You can either use one of the bundled icons or roll your own custom font. Currently available options for bundled icon sets are:
Entypo
by Daniel Bruce (411 icons)EvilIcons
by Alexander Madyankin & Roman Shamin (v1.7.6, 68 icons)FontAwesome
by Dave Gandy (v4.3, 519 icons)Foundation
by ZURB, Inc. (v3.0, 283 icons)Ionicons
by Ben Sperry (v2.0.1, 734 icons)MaterialDesign
by Google, Inc. (v1.0.1, 742 icons)Zocial
by Sam Collins (v1.0, 42 icons)var Icon = require('FontAwesome');
var myIcon = (<Icon name="rocket" size={30} color="#900" style={styles.icon} />)
Either use the size
attribute or a style with fontSize
, defaults to 12. Sets the height of the icon, width depends on the icon aspect ratio, but will most likely be the same.
Either use the color
attribute or a style with color
, defaults to black.
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
flexDirection
justifyContent
alignItems
By combining some of these you can create for example:
It's possible to nest the icons, any child content will appear after the icon, see the button example below.
createIconSet(glyphMap, fontFamily)
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. fontFamily
is the name of the font NOT the filename. Open the font in Font Book.app or similar to learn the name.
var createIconSet = require('createIconSet');
var glyphMap = { 'icon-name': 1234, test: '∆' };
var Icon = createIconSet(glyphMap, 'FontName');
createIconSetFromFontello(config[, fontFamily])
Convenience method to create a custom font based on a fontello config file. Don't forget to import the font as described above and drop the config.json
somewhere convenient in your project.
var require('createIconSetFromFontello');
var fontelloConfig = require('./config.json');
var Icon = createIconSetFromFontello(fontelloConfig);
Try the IconExplorer
project in Examples/IconExplorer
folder, there you can also search for any icon.
var React = require('react-native');
var Icon = require('Ionicons');
var ExampleView = React.createClass({
render: function() {
return <Icon name="person" size={30} color="#4F8EF7" />;
}
};
By nesting a <Text>
element and assigning padding and background color you can achieve a button like appearance. To register taps, just wrap it with a Touchable*
component.
var Icon = require('FontAwesome')
var styles = StyleSheet.create({
icon: {
fontSize: 20,
color: 'white',
paddingVertical: 5,
paddingHorizontal: 8,
borderRadius: 4,
backgroundColor: '#3b5998',
},
text: {
marginLeft: 10,
color: 'white',
fontWeight: '600',
},
});
var button = (
<Icon name="facebook" style={styles.icon}>
<Text style={styles.text}>Login with Facebook</Text>
</Icon>
);
If you already have a icon font with associated CSS file then you can easily generate a icon set with the generate-icon
script.
./node_modules/.bin/generate-icon path/to/styles.css --componentName=MyIcon --fontFamily=myicon > Components/MyIcon.js
Any flags not listed below, like --componentName
and --fontFamily
, will be passed on to the template.
-p
, --prefix
CSS selector prefix [default: ".icon-"]
-t
, --template
Template in lodash format [default: "./template/iconSet.tpl"]
For default template please provide --componentName
and --fontFamily
.
-o
, --output
Save output to file, defaults to STDOUT
This project is licenced under the MIT License.
Any bundled fonts are copyright to their respective authors and mostly under MIT or SIL OFL.
FAQs
Customizable Icons for React Native with support for NavBar/TabBar, image source and full styling.
The npm package react-native-vector-icons receives a total of 525,050 weekly downloads. As such, react-native-vector-icons popularity was classified as popular.
We found that react-native-vector-icons demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.