Skip to content

Instantly share code, notes, and snippets.

@dabit3
Created June 18, 2016 05:47
Show Gist options
  • Save dabit3/ced801df877aa5a743fa508b2d7f6418 to your computer and use it in GitHub Desktop.
Save dabit3/ced801df877aa5a743fa508b2d7f6418 to your computer and use it in GitHub Desktop.
React Native Navigator Experimental Part 3 - TabsRoot.js 2
import React, { Component } from 'react'
import { NavigationExperimental, TabBarIOS } from 'react-native'
const { Reducer: NavigationReducer } = NavigationExperimental
const { JumpToAction } = NavigationReducer.TabsReducer
import Recipes from '../components/Recipes'
import Samples from '../components/Samples'
import Home from '../containers/navRootContainer'
class Tabs extends Component {
_changeTab (i) {
const { dispatch } = this.props
dispatch(JumpToAction(i))
}
_renderTabContent (key) {
switch (key) {
case 'home':
return <Home />
case 'recipes':
return <Recipes />
case 'samples':
return <Samples />
}
}
render () {
const tabs = this.props.tabs.routes.map((tab, i) => {
return (
<TabBarIOS.Item key={tab.key}
icon={tab.icon}
selectedIcon={tab.selectedIcon}
title={tab.title}
onPress={() => this._changeTab(i)}
selected={this.props.tabs.index === i}>
{this._renderTabContent(tab.key)}
</TabBarIOS.Item>
)
})
return (
<TabBarIOS tintColor='black'>
{tabs}
</TabBarIOS>
)
}
}
export default Tabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment