I am new to React Native. I am making a bottom navigation bar. I want to add border bottom when the tab is selected, like the picture below. According to the docs, the indicatorStyle is only applicable on Top Navigation. I am unsure on how to do it.
import {
createBottomTabNavigator,
} from 'react-navigation';
import SettingsScreen from '../settings';
import rootStyles from '../../rootStyles';
const ICON_HOME = require('../../../assets/icon/home.png');
const ICON_USER = require('../../../assets/icon/user_selected.png');
const ICON_CURRENCY = require('../../../assets/icon/currency.png');
export default createBottomTabNavigator({
HomeScreen: {
screen: SettingsScreen,
},
SettingsScreen: {
screen: SettingsScreen,
},
CurrencyScreen: {
screen: SettingsScreen,
},
}, {
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ tintColor }) => {
const { routeName } = navigation.state;
let icon;
switch (routeName) {
case 'HomeScreen':
icon = ICON_HOME;
break;
case 'SettingsScreen':
icon = ICON_USER;
break;
case 'CurrencyScreen':
icon = ICON_CURRENCY;
break;
default: break;
}
return (
<Image
source={icon}
style={{
height: rootStyles.em(2),
width: rootStyles.em(2),
tintColor,
}}
/>
);
},
}),
tabBarPosition: 'bottom',
tabBarOptions: {
showLabel: false,
activeTintColor: rootStyles.PRIMARY_COLOR,
},
tabBarSelectedItemStyle: {
borderBottomWidth: 2,
borderBottomColor: 'red',
},
});
You can do a custom tab for bottomTabNavigator. I have one of these working on a project, take a look:
and my CustomTab component:
Define a state for underlying tab and the view rendered according to this state on CustomTab component. Let me know if this is helpful for you.