react-native - 如果在 react-native CLI 中的选项卡焦点上删除记录,则 TabIcon 计数不会更新
问题描述
关于我的问题:映射视图未在 react-native 的选项卡导航器上更新,我添加了从购物车中删除产品的功能。是的,删除后购物车视图正在减少,但 tabicon 徽章计数仍在最后一次计数,直到我按下购物车以外的任何选项卡。
要将产品购物车添加到对象,是的,它将相应地更新计数。就在从对象中删除记录时,计数不会更新。
我在购物车屏幕上的脚本遵循链接发布的建议:-
componentDidUpdate(prevProps) {
if (prevProps.isFocused !== this.props.isFocused) {
this.setState({ prodData: appGlobal.ObjProduct });
}
}
shouldComponentUpdate(nextProps, nextState) {
if (this.props.prodData !== nextState.prodData) {
return true;
}
return false;
}
在 TabHelpers 类上:-
const tabScreen = createBottomTabNavigator(
{
'Home': {
screen: homeStack,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name='home' size={20} color={tintColor} />
),
},
},
'Favourite': {
screen: favStack,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name='heart' size={20} color={tintColor} />
),
},
},
'Cart': {
screen: cartStack,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<View>
<Icon name='shopping-cart' size={20} color={tintColor} />
{typeof appGlobal.ObjProduct !== 'undefined' && appGlobal.ObjProduct.length > 0 ?
<Badge style={{ position: 'absolute', right: 10, top: 0, height: 13 }}>
<Text style={{ color: 'white', fontSize: 8 }}>{appGlobal.ObjProduct.length}</Text>
</Badge>
: null}
</View>
),
},
},
'Profile': {
screen: profileStack,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name='user' size={20} color={tintColor} />
),
},
}
},
{
initialRouteName: 'Home',
headerMode: 'none',
lazy: false,
backBehavior: 'initialRoute',
swipeEnabled: true,
animationEnabled: true,
tabBarPosition: 'bottom',
tabBarOptions: {
showLabel: true,
showIcon: true,
activeTintColor: '#ffffff',
activeBackgroundColor: '#4961c4',
inactiveTintColor: '#4962a6',
style: {
backgroundColor: '#475691',
},
labelStyle: {
textAlign: 'center',
fontWeight: 'bold',
},
indicatorStyle: {
borderBottomColor: '#FFFFFF',
borderBottomWidth: 2,
},
},
defaultNavigationOptions: ({ navigation }) => ({
tabBarOnPress: ({ navigation, defaultHandler }) => {
navigation.popToTop();
defaultHandler();
},
}),
}
);
export default createAppContainer(tabScreen);
我错过了什么或错误地申请了吗?
解决方案
推荐阅读
- reactjs - 从功能显示卡片组件的问题 [React-Bootstrap]
- javascript - 如何修复预期在反应函数组件结束时返回值的 linter?
- javascript - 变色按钮onclick
- .net-core - .Net Core 依赖注入手动处理使用 implementationFactory Func 创建的对象
- python - Selenium 多文件上传 + Python
- python - 设置结果后,asyncio Future 无限期挂起
- java - 如何使用 Java、Spring boot 读取包含 150K 记录的 excel 文件、验证、持久化 DB 中的行?
- r - 更改示例/虚构数据集中两个变量之间的相关性
- javascript - 尝试使用 jQuery 使用 JSON 数据填充两个链接的 html 下拉对象时出错?
- wso2is - 在 WSO2IS 的 SMSOTP 中输入无效代码时的 NPE