[英]How to add a list count inside TabNavigator in react native
You have two options here: 您在这里有两个选择:
1.Use redux or something else so that your tab component knows its own count, regardless of the route. 1.使用redux或其他方法,使选项卡组件可以知道其自身计数,而与路由无关。
2.You can have a param like badgeCount, which is visible because tabBar or any other navigation option can be defined as a function of the navigation prop: 2,您可以有一个参数如badgeCount,它是可见的,因为可以将tabBar或任何其他导航选项定义为导航道具的函数:
static navigationOptions = {
tabBar: (navigation) => ({
label: 'Home',
icon: ({ tintColor, focused }) =>
<IconBadge
MainElement={
<Ionicons
name={focused ? 'ios-home' : 'ios-home-outline'}
size={26}
style={{ color: tintColor }}
/>
}
badgeNumber={navigation.state.params.badgeCount}
/>,
}),
}
Then you can change the param by calling navigation.setParams({ badgeCount: 123 }). 然后,可以通过调用navigation.setParams({badgeCount:123})来更改参数。
This has been addressed in this Github issue 这已得到解决这个 Github的问题
In your Past Page: 在您的过去页面中:
static navigationOptions = ({navigation}) => ({
title: 'yourTitle',
tabBarLabel: 'Past${navigation.state.params.count}'
})
and it will display new count after you change the count by setParams method: 通过setParams方法更改计数后,它将显示新计数:
navigation.setParams({count: list.length})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.