Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BottomNavigation] Ability to handle custom Icons instead of icon names. #62

Merged
merged 2 commits into from
Dec 21, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/BottomNavigation/BottomNavigationAction.react.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import Icon from '../Icon';
const propTypes = {
/**
* Will be rendered above the label as a content of the action.
* If string, result will be <Icon name={icon} ...rest />
* If ReactElement, will be used as is
*/
icon: PropTypes.string.isRequired,
icon: PropTypes.node.isRequired,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change it for something like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will do it now

/**
* Will be rendered under the icon as a content of the action.
*/
Expand Down Expand Up @@ -79,16 +81,29 @@ function getStyles(props, context) {


class BottomNavigationAction extends PureComponent {

renderIcon(icon, styles, color) {
let element;
if (React.isValidElement(icon)) {
element = icon;
} else {
element = <Icon name={icon} style={styles.icon} color={color} />;
}
return element;
}

render() {
const { icon, label, onPress } = this.props;

const styles = getStyles(this.props, this.context);
const color = StyleSheet.flatten(styles.icon).color;

const iconElement = this.renderIcon(icon, styles, color);

return (
<RippleFeedback onPress={onPress}>
<View style={styles.container}>
<Icon name={icon} style={styles.icon} color={color} />
{iconElement}
<Text style={styles.label}>{label}</Text>
</View>
</RippleFeedback>
Expand Down