Skip to content

Commit decb49a

Browse files
NewOldMaxxotahal
authored andcommitted
[BottomNavigation] Ability to handle custom Icons instead of icon names. (#62)
* [BottomNavigation] Ability to handle custom Icons instead of icon names. * Fix PropTypes.
1 parent f076dc1 commit decb49a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/BottomNavigation/BottomNavigationAction.react.js

100644100755
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import Icon from '../Icon';
1010
const propTypes = {
1111
/**
1212
* Will be rendered above the label as a content of the action.
13+
* If string, result will be <Icon name={icon} ...rest />
14+
* If ReactElement, will be used as is
1315
*/
14-
icon: PropTypes.string.isRequired,
16+
icon: PropTypes.oneOfType([
17+
PropTypes.element,
18+
PropTypes.string,
19+
]).isRequired,
1520
/**
1621
* Will be rendered under the icon as a content of the action.
1722
*/
@@ -79,16 +84,29 @@ function getStyles(props, context) {
7984

8085

8186
class BottomNavigationAction extends PureComponent {
87+
88+
renderIcon(icon, styles, color) {
89+
let element;
90+
if (React.isValidElement(icon)) {
91+
element = icon;
92+
} else {
93+
element = <Icon name={icon} style={styles.icon} color={color} />;
94+
}
95+
return element;
96+
}
97+
8298
render() {
8399
const { icon, label, onPress } = this.props;
84100

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

104+
const iconElement = this.renderIcon(icon, styles, color);
105+
88106
return (
89107
<RippleFeedback onPress={onPress}>
90108
<View style={styles.container}>
91-
<Icon name={icon} style={styles.icon} color={color} />
109+
{iconElement}
92110
<Text style={styles.label}>{label}</Text>
93111
</View>
94112
</RippleFeedback>

0 commit comments

Comments
 (0)