ios - 无法将图像添加到标签栏项目反应导航
问题描述
# 我正在尝试将图像添加到标签栏项目,但无法在反应导航中加载 #
## 我指的是https://github.com/react-navigation/react-navigation/issues/1205#issuecomment-296708338 ##
import React from 'react';
import { Text, View, Image } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation'
import ScreenOne from './ScreenOne';
import Screentwo from './Screentwo';
import Preferences from './Preferences';
const TabNavigator = createBottomTabNavigator(
{
Home: {
screen : ScreenOne,
navigationOptions: {
showLabel: false,
tabBarIcon: <Image style={{ width: 30, height: 30 }} source={require('../images/Help_Header_Icon.png'
)}/>,
showIcon: true,
activeTintColor: '#00000',
inactiveTintColor: '#000000'
}
},
Settings: Screentwo,
Preference: Preferences
},
{
initialRouteName: "Home"
}
);
export default createAppContainer(TabNavigator);
### 期望在标签栏项目中显示图像并隐藏标签栏标签###
解决方案
标签栏图标
React Element 或给定的函数
{ focused: boolean, horizontal: boolean, tintColor: string }
返回一个 React.Node,以显示在选项卡栏中。horizontal
是true
当设备处于横向和false
纵向时。每当设备方向发生变化时,都会重新呈现图标。
用法
{
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor, image }) => {
const { routeName } = navigation.state;
let imagepath;
if (routeName === "Home") {
imagepath = require('../images/Help_Header_Icon.png');
} else if (routeName === "Settings") {
imagepath = require('../images/Settings.png');
} else if (routeName === "Preference") {
imagepath = require('../images/Preference.png');
}
return (
<Image
style={{ width: 30, height: 30, resizeMode: "stretch" }}
source={imagepath}
/>
);
推荐阅读
- mongodb - MongoDB Atlas 未连接到我的 golang 应用程序
- javascript - 如果未找到打印,则检查数组中是否存在元素
- node.js - 错误:在 Gaxios 上找不到。
尝试从 Gmail 获取历史记录列表时 - c# - Automapper - IncludeBase 抽象通用父原因“...不是源自”错误
- flutter - 使用命令 flutter build apk 时如何解决音频播放器的配置问题?
- python - 使用逻辑运算符创建新列
- c++ - 使用可变参数存储 C++ lambda
- javascript - 无法读取未定义 MongoDB 的属性“insertOne”
- programming-languages - 从软件工程开始
- linux - Snort 签名说明