javascript - 底部选项卡导航器背景图像
问题描述
我正在使用React Navigation 3
. 目前我的bottomTabNavigator
项目中有一个。我想为它设置背景图像或艺术。我的标题非常简单,因为我使用了一个名为的属性headerBackground
并将一个反应组件传递给它并且它可以工作,但对于bottomTab 则不是这样。
我设法通过使用使其以某种方式工作,tabBarComponent
因此图像呈现正常,但问题是我的标签消失了。
有没有正确的方法来设置背景图像tabNavigator
?
这是我当前的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}/>
只需制作组件并在其中创建图标或文本并渲染它。在组件下,您可以通过以下方式导航到其他屏幕this.props.navigation.navigate('desirescreen-route');
推荐阅读
- python - Pyinstaller 问题
- angular - 角度应用程序中的请求返回状态 400
- sql - 为第 1 列和第 2 列的每个新组合生成新 ID
- azure - ADF 映射数据流失败并出现 BatchUpdateException
- c# - OpenXML 添加的图像位于文档媒体文件夹中,但未显示在 Office 中
- matlab - Jupyter notebook MATLAB 内核:运行,但不显示输出
- javascript - React Native,如何再次使 redux 状态为 false
- python - 我无法使用 tf.keras.util.get_file 下载图像数据集
- lua - 触摸任何同名对象时如何运行代码
- c# - 仅在 if else 条件下在数组中查找最大值