react-native-vector-icons
Version:
Customizable Icons for React Native with support for NavBar/TabBar/ToolbarAndroid, image source and full styling.
1 lines • 4.98 kB
JavaScript
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");Object.defineProperty(exports,"__esModule",{value:true});exports.default=createTabBarItemIOSComponent;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf3=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _isEqual=_interopRequireDefault(require("lodash/isEqual"));var _pick=_interopRequireDefault(require("lodash/pick"));var _react=_interopRequireWildcard(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));var _reactNative=require("./react-native");var _jsxFileName="/home/travis/build/oblador/react-native-vector-icons/lib/tab-bar-item-ios.js";var ICON_PROP_NAMES=['iconName','iconSize','iconColor'];var SELECTED_ICON_PROP_NAMES=ICON_PROP_NAMES.concat(['selectedIconName','selectedIconColor']);var arePropsEqual=function arePropsEqual(keys){return function(prevProps,nextProps){return(0,_isEqual.default)((0,_pick.default)(prevProps,keys),(0,_pick.default)(nextProps,keys));};};var areIconPropsEqual=arePropsEqual(ICON_PROP_NAMES);var areSelectedIconPropsEqual=arePropsEqual(SELECTED_ICON_PROP_NAMES);function createTabBarItemIOSComponent(IconNamePropType,getImageSource){var _class,_temp;return _temp=_class=function(_PureComponent){(0,_inherits2.default)(TabBarItemIOS,_PureComponent);function TabBarItemIOS(){var _getPrototypeOf2;var _this;(0,_classCallCheck2.default)(this,TabBarItemIOS);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=(0,_possibleConstructorReturn2.default)(this,(_getPrototypeOf2=(0,_getPrototypeOf3.default)(TabBarItemIOS)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.state={icon:undefined,selectedIcon:undefined};return _this;}(0,_createClass2.default)(TabBarItemIOS,[{key:"componentDidMount",value:function componentDidMount(){this.updateIconSource();this.updateSelectedIconSource();}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){if(!areIconPropsEqual(prevProps,this.props)){this.updateIconSource();}if(!areSelectedIconPropsEqual(prevProps,this.props)){this.updateSelectedIconSource();}}},{key:"updateIconSource",value:function updateIconSource(){var _this$props,iconName,iconSize,iconColor,icon;return _regenerator.default.async(function updateIconSource$(_context){while(1){switch(_context.prev=_context.next){case 0:_this$props=this.props,iconName=_this$props.iconName,iconSize=_this$props.iconSize,iconColor=_this$props.iconColor;if(!iconName){_context.next=8;break;}_context.next=4;return _regenerator.default.awrap(getImageSource(iconName,iconSize,iconColor));case 4:icon=_context.sent;this.setState({icon:icon});_context.next=9;break;case 8:if(this.state.icon){this.setState({icon:undefined});}case 9:case"end":return _context.stop();}}},null,this);}},{key:"updateSelectedIconSource",value:function updateSelectedIconSource(){var _this$props2,iconName,iconColor,iconSize,selectedIconName,selectedIconColor,selectedIcon;return _regenerator.default.async(function updateSelectedIconSource$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_this$props2=this.props,iconName=_this$props2.iconName,iconColor=_this$props2.iconColor,iconSize=_this$props2.iconSize,selectedIconName=_this$props2.selectedIconName,selectedIconColor=_this$props2.selectedIconColor;if(!(selectedIconName||selectedIconColor)){_context2.next=8;break;}_context2.next=4;return _regenerator.default.awrap(getImageSource(selectedIconName||iconName,iconSize,selectedIconColor||iconColor));case 4:selectedIcon=_context2.sent;this.setState({selectedIcon:selectedIcon});_context2.next=9;break;case 8:if(this.state.selectedIcon){this.setState({selectedIcon:undefined});}case 9:case"end":return _context2.stop();}}},null,this);}},{key:"render",value:function render(){return _react.default.createElement(_reactNative.TabBarIOS.Item,(0,_extends2.default)({},this.state,this.props,{__source:{fileName:_jsxFileName,lineNumber:93}}));}}]);return TabBarItemIOS;}(_react.PureComponent),_class.propTypes={iconName:IconNamePropType.isRequired,selectedIconName:IconNamePropType,iconSize:_propTypes.default.number,iconColor:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.number]),selectedIconColor:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.number])},_class.defaultProps={iconSize:30},_temp;}