Skip to content

Commit

Permalink
renderIcon is a weird mix of optional (TabNavigatorIcon has a default…
Browse files Browse the repository at this point in the history
… value, TabNavigator constantly checks item.props.renderIcon) and non-optional (marked as func.isRequired). On top of that, the default value of renderIcon returns a <View />, which does not accept the defaultSelectedIcon stylesheet's tintColor (which is only allowed on <Image /> elements.) (ptomasroos#77)

This correctly makes renderIcon optional again in all senses of the word, and ensures the code works without warnings in such cases. (I see some references on the issue tracker about this problem.)

This isn't important in shipping code (where you'll most likely have icons), but is important when first setting it up without icons and seeing scary looking warnings.
The renderIcon is optional in many ways (has a default value that returns a
  • Loading branch information
mikelambert committed Sep 28, 2016
1 parent 5aec42b commit ce05349
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export default class Tab extends React.Component {

render() {
let { title, badge } = this.props;
let icon = React.Children.only(this.props.children);
let icon = null;
if (React.Children.count(this.props.children) > 0) {
icon = React.Children.only(this.props.children);
}

if (title) {
title =
Expand Down
3 changes: 1 addition & 2 deletions TabNavigatorItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

export default class TabNavigatorItem extends React.Component {
static propTypes = {
renderIcon: PropTypes.func.isRequired,
renderIcon: PropTypes.func,
renderSelectedIcon: PropTypes.func,
badgeText: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
renderBadge: PropTypes.func,
Expand All @@ -24,7 +24,6 @@ export default class TabNavigatorItem extends React.Component {
};

static defaultProps = {
renderIcon: () => <View />,
};

render() {
Expand Down

0 comments on commit ce05349

Please sign in to comment.