v2 customize tabbar style (I want to use component instead of icon)
hi all,
I am using native navigation v2.
I want to customize TabBar's style.
I want to use component instead of icon How can I do this?
I want to create a tabbar area like the one shown in the picture.

Would also be interested in this. As far as I can see it, even when trying to just use the icon there is no background styling on
{
options: {
bottomTab: {
icon: ...,
(backgroundColor?)
or am I mistaken?
not sure if this is possible at this point in time... but I wrote my own custom component by rendering a row of Touchables at the bottom that calls a function that sets the state of the main container view to render the corresponding tab component
@yuannypants How did you write? Can I see pictures and code?
Was lazy so I just regurgitated some of my code (esp the styling), provides the functionality that you mentioned + tab customisation and badge support as a separate component (TabButton). Screen1 - Screen5 are your tab components, be sure to import them or define them in the same file (not recommended).
export default class MainScreen extends Component {
constructor(props) {
super(props);
this.selectTab = this.selectTab.bind(this);
this.state = {
selectedTab: 1
}
}
render() {
return (
<View style={mainStyles.main}>
<View style={mainStyles.tabContainer}>
{
this.state.selectedTab===1 ?
<Screen1 originComponentId={ this.props.componentId }/> :
this.state.selectedTab===2 ?
<Screen2 originComponentId={ this.props.componentId }/> :
this.state.selectedTab===3 ?
<Screen3 originComponentId={ this.props.componentId }/> :
this.state.selectedTab===4 &&
<Screen4 originComponentId={ this.props.componentId }/>
}
</View>
<View style={mainStyles.bottomTabsContainer}>
<TabButton
currIndex={this.state.selectedTab}
index={1}
tabIconSource={require('./assets/img/tabIcons/tab1Icon.png')}
tabText={'Tab 1'}
badgeContent={0}
selectTab={index => this.selectTab(index)}
/>
<TabButton
currIndex={this.state.selectedTab}
index={2}
tabIconSource={'require(./assets/img/tabIcons/tab2Icon.png')}
tabText={'Tab 2'}
badgeContent={0}
selectTab={index => this.selectTab(index)}
/>
<TabButton
currIndex={this.state.selectedTab}
index={3}
tabIconSource={require('./assets/img/tabIcons/tab3Icon.png')}
tabText={'Tab 3'}
badgeContent={0}
selectTab={index => this.selectTab(index)}
/>
<TabButton
currIndex={this.state.selectedTab}
index={4}
tabIconSource={require('./assets/img/tabIcons/tab4Icon.png')}
tabText={'Tab 4'}
badgeContent={0}
selectTab={index => this.selectTab(index)}
/>
<TabButton
currIndex={this.state.selectedTab}
index={5}
tabIconSource={require('./assets/img/tabIcons/tab5Icon.png')}
tabText={'Tab 5'}
badgeContent={0}
selectTab={index => this.selectTab(index)}
/>
</View>
</View>
);
};
selectTab = (tabId) => {
this.setState({selectedTab: tabId});
switch (tabId) {
case 1: // Tab 1
// any other action you require other than setState,
// e.g. mergeOptions to change topbar content?
break;
case 2: // Tab2
break;
case 3: // Tab3
break;
case 4: // Tab4
break;
}
}
class TabButton extends Component {
constructor(props) {
super(props);
}
render() {
return (
<TouchableHighlight style={{flex:1, alignItems: 'center', justifyContent: 'center'}} underlayColor={'transparent'} onPress={() => this.props.selectTab(this.props.index)}>
<View style={mainStyles.bottomTabContainer}>
<Image
source={this.props.tabIconSource}
style={
this.props.index!==0 ?
this.props.currIndex === this.props.index ?
mainStyles.selectedTabIcon :
mainStyles.tabIcon :
this.props.currIndex === this.props.index ?
mainStyles.selectedListTabIcon :
mainStyles.listTabIcon
/>
<Text style={this.props.currIndex === this.props.index ? mainStyles.selectedTabTitle : mainStyles.tabTitle}>{this.props.tabText}</Text>
{
this.props.badgeContent!==0 &&
<View style={this.props.badgeContent<10 ? mainStyles.badgeContainer : mainStyles.extendedBadgeContainer}>
<Text style={mainStyles.badge}>
{this.props.badgeContent<99 ? this.props.badgeContent : '99+'}
</Text>
</View>
}
</View>
</TouchableHighlight>
)
}
}
const mainStyles = StyleSheet.create({
main: {
flex: 1
},
tabContainer: {
position: 'absolute',
top:0,
left:0,
height: deviceHeight-49-55,
width: deviceWidth,
},
bottomTabsContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
position: 'absolute',
left:0,
bottom:0,
height: 50,
width: deviceWidth,
backgroundColor: 'white',
borderTopWidth: 0.5,
borderTopColor: '#b6b6b6'
},
bottomTabContainer: {
height: 50,
width: 50,
alignItems: 'center',
justifyContent: 'flex-end'
},
tabIcon: {
height: 23,
width: 23,
resizeMode: 'contain',
tintColor: '#767676',
},
selectedTabIcon: {
height: 24,
width: 24,
resizeMode: 'contain',
tintColor: '#6DCDD7',
},
listTabIcon: {
height: 48,
width: 48,
resizeMode: 'contain',
tintColor: '#767676',
},
selectedListTabIcon: {
height: 48,
width: 48,
resizeMode: 'contain',
tintColor: '#6DCDD7',
},
tabTitle: {
fontFamily: 'Nunito-Bold',
fontSize: 13,
color: '#767676',
marginBottom: 3
},
selectedTabTitle: {
fontFamily: 'Nunito-Bold',
fontSize: 14,
color: '#6DCDD7',
marginBottom: 3
},
badgeContainer: {
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
top: 2,
right: 6,
backgroundColor: '#FF8484',
height: 16,
width: 16,
borderRadius: 8,
},
extendedBadgeContainer: {
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
top: -2,
right: -6,
backgroundColor: '#FF8484',
height: 16,
width: 22,
borderRadius: 8,
},
badge: {
fontFamily: 'Nunito-Bold',
fontSize: 12,
color: 'white'
}
});
const mainStyles = StyleSheet.create({
main: {
flex: 1
},
tabContainer: {
position: 'absolute',
top:0,
left:0,
height: deviceHeight-49-55,
width: deviceWidth,
},
bottomTabsContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
position: 'absolute',
left:0,
bottom:0,
height: 50,
width: deviceWidth,
backgroundColor: 'white',
borderTopWidth: 0.5,
borderTopColor: '#b6b6b6'
},
bottomTabContainer: {
height: 50,
width: 50,
alignItems: 'center',
justifyContent: 'flex-end'
},
tabIcon: {
height: 23,
width: 23,
resizeMode: 'contain',
tintColor: '#767676',
},
selectedTabIcon: {
height: 24,
width: 24,
resizeMode: 'contain',
tintColor: '#6DCDD7',
},
listTabIcon: {
height: 48,
width: 48,
resizeMode: 'contain',
tintColor: '#767676',
},
selectedListTabIcon: {
height: 48,
width: 48,
resizeMode: 'contain',
tintColor: '#6DCDD7',
},
tabTitle: {
fontFamily: 'Nunito-Bold',
fontSize: 13,
color: '#767676',
marginBottom: 3
},
selectedTabTitle: {
fontFamily: 'Nunito-Bold',
fontSize: 14,
color: '#6DCDD7',
marginBottom: 3
},
badgeContainer: {
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
top: 2,
right: 6,
backgroundColor: '#FF8484',
height: 16,
width: 16,
borderRadius: 8,
},
extendedBadgeContainer: {
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
top: -2,
right: -6,
backgroundColor: '#FF8484',
height: 16,
width: 22,
borderRadius: 8,
},
badge: {
fontFamily: 'Nunito-Bold',
fontSize: 12,
color: 'white'
}
});
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.
i am interested in too
I'm also searching for a way of doing this that isn't too hacky.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
The issue has been closed for inactivity.
+1
Has anyone found anything not too hacky to achieve this?
I need too something like that.
+1
I'm looking to do the same thing, but in the navbar. I don't know how to access the onPress event with a custom component... Any ideas ? Thanks ;)
+1
I found a tutorial on youtube. Hope this help https://www.youtube.com/watch?v=qwkeM0W2dfo
I'm looking to do the same thing, but in the navbar. I don't know how to access the onPress event with a custom component... Any ideas ? Thanks ;)
Same problem