Skip to content

Commit

Permalink
Ignore null children in the tab-bar. (ptomasroos#86)
Browse files Browse the repository at this point in the history
This allows you to render tab items conditonally since the false
condition returns null in that case.
  • Loading branch information
mvantellingen authored and mikelambert committed Sep 28, 2016
1 parent ce05349 commit a22acea
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions TabNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export default class TabNavigator extends React.Component {
_updateRenderedSceneKeys(children, oldSceneKeys = Set()): Set {
let newSceneKeys = Set().asMutable();
React.Children.forEach(children, (item, index) => {
if (item === null) {
return;
}
let key = this._getSceneKey(item, index);
if (oldSceneKeys.has(key) || item.props.selected) {
newSceneKeys.add(key);
Expand All @@ -64,6 +67,9 @@ export default class TabNavigator extends React.Component {
let scenes = [];

React.Children.forEach(children, (item, index) => {
if (item === null) {
return;
}
let sceneKey = this._getSceneKey(item, index);
if (!this.state.renderedSceneKeys.has(sceneKey)) {
return;
Expand All @@ -90,6 +96,9 @@ export default class TabNavigator extends React.Component {

_renderTab(item) {
let icon;
if (item === null) {
return;
}
if (item.props.selected) {
if (item.props.renderSelectedIcon) {
icon = item.props.renderSelectedIcon();
Expand Down

0 comments on commit a22acea

Please sign in to comment.