[英]Bottom Tab Navigator background image
Im using React Navigation 3
.我正在使用React Navigation 3
。 Currently I have a bottomTabNavigator
in my project.目前,我的项目中有一个bottomTabNavigator
。 I want to set a background image or art for it.我想为它设置背景图片或艺术。 My header was pretty much straight forward because I used a property called headerBackground
and I passed a react component to it and it works, but its not the case for bottomTab.我的标题非常简单,因为我使用了一个名为headerBackground
的属性,并且我向它传递了一个 react 组件并且它可以工作,但对于 bottomTab 则不是这种情况。
I managed to make it work somehow by using tabBarComponent
so the image renders ok, but the problem is that my tabs disappear.我设法通过使用tabBarComponent
使其以某种方式工作,因此图像呈现正常,但问题是我的选项卡消失了。
Is there a proper way to set a background image to tabNavigator
?是否有将背景图像设置为tabNavigator
的正确方法?
Here is my current tabNavigator
code:这是我当前的tabNavigator
代码:
import React from 'react'; import { createBottomTabNavigator, createAppContainer } from 'react-navigation'; import Profile from "../components/Profile"; import { Image, View } from 'react-native'; const Tab = createBottomTabNavigator( { Profile: { screen: Profile, navigationOptions: { title: 'Home', tabBarIcon: ({ tintColor }) => ( <Image source={require('../../images/home-ico.png')} style={{width: 25, height: 25, resizeMode: 'contain'}} /> ) } }, Partidos: { screen: Profile, navigationOptions: { title: 'Home', tabBarIcon: ({ tintColor }) => ( <Image source={require('../../images/home-ico.png')} style={{width: 25, height: 25, resizeMode: 'contain'}} /> ) } }, Grupos: { screen: Profile, navigationOptions: { title: 'Home', tabBarIcon: ({ tintColor }) => ( <Image source={require('../../images/home-ico.png')} style={{width: 25, height: 25, resizeMode: 'contain'}} /> ) } }, Reserva: { screen: Profile, navigationOptions: { title: 'Home', tabBarIcon: ({ tintColor }) => ( <Image source={require('../../images/home-ico.png')} style={{width: 25, height: 25, resizeMode: 'contain'}} /> ) } } }, { tabBarOptions:{ style: { backgroundColor: '#c2b464', }, showLabel: false }, tabBarComponent: props =>{ return( <View> <Image style={{ width: '100%', height: 50 }} source={ require('../../images/tabs-bg.png')}/> </View> ); } } ); export default createAppContainer(Tab);
tabBarComponent: props =><BottomNavigator {...props}/>
Just make the component and create the Icon or Text in and render it.只需制作组件并在其中创建图标或文本并渲染它。 Under component u can navigate to other screen by this.props.navigation.navigate('desirescreen-route');
在组件下你可以通过this.props.navigation.navigate('desirescreen-route');
导航到其他屏幕this.props.navigation.navigate('desirescreen-route');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.