how can I change to FontAwesome when I use Icon component?
Hey, that has been in our roadmap for quite some time. Will add it with the next release. If you need it urgently though, go to Widgets/Icon.js and set whichever Icon set you wish to use.
Cool. Can I expand the scope of this issue to include all the available icon frameworks provided by react-native-vector-icons?
https://github.com/oblador/react-native-vector-icons#bundled-icon-sets
Yes, sure you can. You just need to define the Icon variable to your desired Icon family, and you're set.
Hi, you can set the variable in light.js to your desired Icon family. Only the ones available in react-native-vector-icons are supported.
According to the IconNB implementation:
<Icon theme={{ iconFamily: 'FontAwesome' }} name='fontawesome-name' />
@melvinsg It doesn't work for me.
Make sure you are using the native base version of the component:
import { Icon } from 'native-base'
then you can override the theme property defaults
import {Platform} from 'react-native'
const fontAwesome = {
iconFamily: 'FontAwesome',
iconFontSize: (Platform.OS === 'ios' ) ? 30 : 28,
iconMargin: 7,
iconLineHeight: (Platform.OS === 'ios' ) ? 37 : 30,
}
Now you can use it
<Icon theme={fontAwesome} name='fontawesome-name' />
Seems like theme prop is no longer supported. I made a custom Icon class for using other icon families:
import React, { Component } from 'react'
import { StyleProvider, getTheme, Icon } from 'native-base'
type Props = {
family?: string,
name: string,
style?: any
}
export default class MIcon extends Component<Props> {
render () {
const { family, name, style } = this.props
const icon = <Icon name={name} style={style} />
if (family) {
const customTheme = getTheme({iconFamily: family})
return <StyleProvider style={customTheme}>{icon}</StyleProvider>
} else {
return icon
}
}
}
Example:
<Icon
family='FontAwesome'
name='pause-circle-o'
style={{ fontSize: 20, color: 'red' }]}
/>
For js version:
import React, { Component } from 'react';
import { ViewPropTypes } from 'react-native';
import { StyleProvider, getTheme, Icon } from 'native-base';
import PropTypes from 'prop-types';
export default class IHIcon extends Component {
render () {
const { family, name, style } = this.props;
const icon = <Icon name={name} style={style} />
if (family) {
const customTheme = getTheme({iconFamily: family})
return <StyleProvider style={customTheme}>{icon}</StyleProvider>
} else {
return icon
}
}
}
IHIcon.propTypes = {
family: PropTypes.string,
name: PropTypes.string.isRequired,
style: PropTypes.any
};
My NativeBase
"native-base": "^2.3.9",
I see in node_modules/native-base/src/basic/IconNB.js
IconNB.propTypes = {
style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
type: PropTypes.oneOf(["Ionicons", "Entypo", "FontAwesome", "Foundation", "MaterialIcons", "MaterialCommunityIcons", "Octicons", "Zocial", "SimpleLineIcons"]),
};
and i usage <Icon type="FontAwesome" name="calendar-plus-o" /> and this work for me
Thanks NativeBase!
Why isn't this in the docs?
<Icon type="FontAwesome" name="calendar-plus-o" />
exactly. There is a lot of stuff in NB that is not in the docs. You have to read the comments in code to find out
Vector Icons are Native Base dependency, so it's even easier to include the needed collection:
import FontAwesome from 'react-native-vector-icons/FontAwesome'
<FontAwesome name='calendar-plus-o' />
Most helpful comment
Seems like
themeprop is no longer supported. I made a custom Icon class for using other icon families:Example: