【发布时间】:2021-10-25 14:21:26
【问题描述】:
在构建自定义 Tab.Screen 时,我尝试传递自定义 tabBarIcon。当图标呈现时,它不会导航到组件TestScreen。在docs 对tabBarIcon 我的理解中Tab.Screen 应该写成:
<Tab.Screen
name={routes.FOO}
component={TestScreen}
options={{
tabBarIcon: ({ focused }) => (
<TouchableOpacity>
<View style={styles.actionButton}>
<Image source={plus} style={styles.imageIcon} />
</View>
</TouchableOpacity>
),
}}
/>
当我省略 options:
<Tab.Screen
name={routes.FOO}
component={TestScreen}
/>
onClick 在单击时呈现组件。当我阅读Options for screens 的文档时,它提到screenOptions 应该在导航器或组上传递。我试着看看能不能找到类似的问答:
- React native react-navigation tabBarIcon does not display
- Why Is My Component not Rendering Within my Tab.Screen?
但我无法看到我的错误在哪里。
我目前的依赖:
"dependencies": {
"@react-navigation/bottom-tabs": "^6.0.5",
"@react-navigation/native": "^6.0.2",
"expo": "~42.0.1",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-gesture-handler": "^1.10.3",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.4.0",
"react-native-web": "~0.13.12"
},
"devDependencies": {
"@babel/core": "^7.9.0"
},
如何让我的自定义图标呈现并导航到正确的组件?
【问题讨论】:
标签: react-native expo react-navigation react-navigation-v6