import {BottomTabBar, createBottomTabNavigator} from
'react-navigation-tabs'
;
const TABS = {
Page1: {
screen: Page1,
navigationOptions: {
tabBarLabel:
'Page10'
,
tabBarIcon: ({tintColor, focused}) => (
<Ionicons
name={focused ?
'ios-home'
:
'ios-home-outline'
}
size={26}
style={{color: tintColor}}
/>
),
}
},
Page2: {
screen: Page2,
navigationOptions: {
tabBarLabel:
'Page2'
,
tabBarIcon: ({tintColor, focused}) => (
<Ionicons
name={focused ?
'ios-people'
:
'ios-people-outline'
}
size={26}
style={{color: tintColor}}
/>
),
}
},
Page3: {
screen: Page3,
navigationOptions: {
tabBarLabel:
'Page3'
,
tabBarIcon: ({tintColor, focused}) => (
<Ionicons
name={focused ?
'ios-chatboxes'
:
'ios-chatboxes-outline'
}
size={26}
style={{color: tintColor}}
/>
),
}
},
};
export
default
class DynamicTabNavigator extends React.Component {
constructor(props) {
super
(props);
console.disableYellowBox =
true
;
}
_tabNavigator() {
let tabs = {};
if
(
this
.props.navigation.state.params.tabs) {
this
.props.navigation.state.params.tabs.forEach(e => {
tabs[e] = TABS[e];
})
}
else
{
const {Page1, Page2} = TABS;
tabs = {Page1, Page2};
Page1.navigationOptions.tabBarLabel =
'P1'
;
}
return
createBottomTabNavigator(tabs, {
tabBarComponent: TabBarComponent,
tabBarOptions: {
activeTintColor: Platform.OS ===
'ios'
?
'#e91e63'
:
'#fff'
,
}
});
}
render() {
const Tabs =
this
._tabNavigator();
return
(
<Tabs/>
);
}
}
class TabBarComponent extends React.Component {
constructor(props) {
super
(props);
this
.theme = {
tintColor: props.activeTintColor,
updateTime:
new
Date().getTime()
}
}
render() {
const {routes, index} =
this
.props.navigation.state;
if
(routes[index].params) {
const {theme} = routes[index].params;
if
(theme && theme.updateTime >
this
.theme.updateTime) {
this
.theme = theme;
}
}
return
(
<BottomTabBar
{...
this
.props}
activeTintColor={
this
.theme.tintColor ||
this
.props.activeTintColor}
/>
);
}
}