@expo/vector-icons
Version:
Built-in support for 10 popular icon fonts and the tooling to create your own Icon components from your font and glyph map. This is a wrapper around react-native-vector-icons to make it compatible with Expo.
58 lines (51 loc) • 1.61 kB
JavaScript
import { isEqual, pick } from 'lodash';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TabBarIOS } from './react-native';
export default function createTabBarItemIOSComponent(
IconNamePropType,
getImageSource
) {
return class TabBarItemIOS extends Component {
static propTypes = {
iconName: IconNamePropType.isRequired,
selectedIconName: IconNamePropType,
iconSize: PropTypes.number,
iconColor: PropTypes.string,
selectedIconColor: PropTypes.string,
};
static defaultProps = {
iconSize: 30,
};
updateIconSources(props) {
if (props.iconName) {
getImageSource(
props.iconName,
props.iconSize,
props.iconColor
).then(icon => this.setState({ icon }));
}
if (props.selectedIconName || props.selectedIconColor) {
const selectedIconName = props.selectedIconName || props.iconName;
const selectedIconColor = props.selectedIconColor || props.iconColor;
getImageSource(
selectedIconName,
props.iconSize,
selectedIconColor
).then(selectedIcon => this.setState({ selectedIcon }));
}
}
componentWillMount() {
this.updateIconSources(this.props);
}
componentWillReceiveProps(nextProps) {
const keys = Object.keys(TabBarItemIOS.propTypes);
if (!isEqual(pick(nextProps, keys), pick(this.props, keys))) {
this.updateIconSources(nextProps);
}
}
render() {
return <TabBarIOS.Item {...this.props} {...this.state} />;
}
};
}