react-native - 如何找到 React Navigation TabBarIcon/TabBar 元素中使用的“renderIcon”函数的规范?
问题描述
使用了此功能,但我找不到它的定义位置。我还看到很多使用此代码的教程 - 所以我不确定人们如何理解它是如何使用的。
我从源代码中提取了这个:
20 export default function TabBarIcon({
21 activeOpacity,
22 inactiveOpacity,
23 activeTintColor,
24 inactiveTintColor,
25 renderIcon, <---- HERE IT IS BEING USED IN THE REACT NAVIGATION SOURCE CODE
26 size,
27 style,
28 }: Props) {
29 // We render the icon twice at the same position on top of each other:
30 // active and inactive one, so we can fade between them.
31 return (
32 <View style={style}>
33 <View style={[styles.icon, { opacity: activeOpacity }]}>
34 {renderIcon({
35 focused: true,
36 size,
37 color: activeTintColor,
38 })}
39 </View>
40 <View style={[styles.icon, { opacity: inactiveOpacity }]}>
41 {renderIcon({
42 focused: false,
43 size,
44 color: inactiveTintColor,
45 })}
46 </View>
47 </View>
48 );
49 }
找不到这种方法的来源,只有它被使用过。文档中的任何地方都没有提到这种方法 - 我可以找到。
我错过了什么?
解决方案
您可以使用导航操作来实现相同的行为。我写了一篇简短的博客,解释了为什么我们不能只使用升级指南中提到的条件模板
https://omidborjian.medium.com/switch-navigator-in-react-navigation-5-1d2bf34775b9
import { CommonActions } from '@react-navigation/native';
navigation.dispatch(
CommonActions.reset({
index: 1,
routes: [
{ name: routeName, params: params }
],
})
);
推荐阅读
- azure-api-management - Azure API 管理和身份验证
- maven - 无法使用 atlassian SDK 启动 Jira 8.10
- r - R:使用分组将数据框写入文本
- python - 使用 pip 安装 PyGame 遇到“不存在 SETUP 文件”
- javascript - Javascript:而不是用按钮控制滑块向下滚动或向上滚动
- vb.net - 将多行文本参数从 VB.NET 传递到 npgsql
- windows - 无法在 Visual C++ (2017) 中设置 UDP_CHECKSUM_COVERAGE 选项
- python - MongoDB 可以在获得 find() 结果之前更改 db 中的值(而不是更新)?皮蒙哥
- xslt - 使用 XSLT 删除/替换无效字符
- javascript - 如何对直接在浏览器中导入的嵌入式 javascript 进行单元测试