Skip to content

Instantly share code, notes, and snippets.

@callmephilip
Created May 18, 2016 15:33
Show Gist options
  • Save callmephilip/39c594486aba0747112271f456ab7349 to your computer and use it in GitHub Desktop.
Save callmephilip/39c594486aba0747112271f456ab7349 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { TabBarIOS, NavigationExperimental } from 'react-native';
import Feed from '../Feed';
import { connect } from 'react-redux';
const { Reducer: NavigationReducer } = NavigationExperimental;
const { JumpToAction } = NavigationReducer.TabsReducer;
class ApplicationTabs extends Component {
_renderTabContent(tab) {
// XX: This is a simplified version of _renderTabContent
if (tab.key === 'feed') {
return (
<Feed />
);
}
}
render() {
const children = this.props.navigation.children.map( (tab, i) => {
return (
<TabBarIOS.Item key={tab.key}
icon={tab.icon}
selectedIcon={tab.selectedIcon}
title={tab.title} onPress={ () => this.props.onNavigate(JumpToAction(i)) }
selected={this.props.navigation.index === i}>
{ this._renderTabContent(tab) }
</TabBarIOS.Item>
);
});
return (
<TabBarIOS tintColor="black">
{children}
</TabBarIOS>
);
}
}
const mapDispatchToProps = (dispatch) => {
return {
dispatch,
onNavigate: (action) => dispatch(action)
};
}
const mapStateToProps = (state) => {
return {
navigation: state.get('tabs')
};
}
export default connect(mapStateToProps, mapDispatchToProps)(ApplicationTabs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment