Skip to content

Instantly share code, notes, and snippets.

@brunovianarezende
Created June 23, 2017 17:59
Show Gist options
  • Select an option

  • Save brunovianarezende/6f65249ede3a68a7ef8d1f5698e7955d to your computer and use it in GitHub Desktop.

Select an option

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
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