Created
June 23, 2017 17:59
-
-
Save brunovianarezende/6f65249ede3a68a7ef8d1f5698e7955d to your computer and use it in GitHub Desktop.
How to create a custom Icon component based on NativeBase.Icon that accepts a 'iconFamily' parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import PropTypes from 'prop-types' | |
| import {Icon, StyleProvider, getTheme } from 'native-base'; | |
| class MyIcon extends React.Component { | |
| render() { | |
| if(this.props.iconFamily) { | |
| return ( | |
| <StyleProvider style={getTheme({iconFamily: this.props.iconFamily})}> | |
| {this._renderIcon()} | |
| </StyleProvider> | |
| ) | |
| } else { | |
| return this._renderIcon(); | |
| } | |
| } | |
| _renderIcon() { | |
| const {['iconFamily']: _, ...newProps} = this.props; | |
| return ( | |
| <Icon {...newProps} /> | |
| ) | |
| } | |
| } | |
| MyIcon.propTypes = { | |
| ...Icon.propTypes, | |
| iconFamily: PropTypes.string, | |
| }; | |
| export default MyIcon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment