Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如果在react native CLI的选项卡焦点上删除记录,则不会更新选项卡图标计数_React Native - Fatal编程技术网

React native 如果在react native CLI的选项卡焦点上删除记录,则不会更新选项卡图标计数

React native 如果在react native CLI的选项卡焦点上删除记录,则不会更新选项卡图标计数,react-native,React Native,关于我的问题,我添加了从购物车中删除产品的功能。是的,购物车视图在删除后正在减少,但tabicon徽章计数仍然是最后一次计数,直到我按下购物车以外的任何选项卡 对于将产品购物车添加到对象,是,它将相应地更新计数。当从对象中删除记录时,计数不会更新 我在购物车屏幕上的脚本有以下链接帖子的建议:- componentDidUpdate(prevProps) { if (prevProps.isFocused !== this.props.isFocused) { this.setSta

关于我的问题,我添加了从购物车中删除产品的功能。是的,购物车视图在删除后正在减少,但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);
const tabScreen=createBottomTabNavigator(
{
“家”:{
屏幕:homeStack,
导航选项:{
tabBarIcon:({tintColor})=>(
),
},
},
“最爱”:{
屏幕:favStack,
导航选项:{
tabBarIcon:({tintColor})=>(
),
},
},
“购物车”:{
屏幕:cartStack,
导航选项:{
tabBarIcon:({tintColor})=>(
{typeof appGlobal.ObjProduct!='undefined'&&appGlobal.ObjProduct.length>0?
{appGlobal.objpproduct.length}
:null}
),
},
},
“个人资料”:{
屏幕:profileStack,
导航选项:{
tabBarIcon:({tintColor})=>(
),
},
}
},
{
initialRouteName:“主页”,
headerMode:“无”,
懒惰:错,
backBehavior:'initialRoute',
是的,
animationEnabled:没错,
tabBarPosition:'底部',
选项卡选项:{
showLabel:true,
showIcon:没错,
activeTintColor:“#ffffff”,
activeBackgroundColor:“#4961c4”,
颜色:“#4962a6”,
风格:{
背景颜色:“#475691”,
},
标签样式:{
textAlign:'中心',
fontWeight:'粗体',
},
指标类型:{
borderBottomColor:“#FFFFFF”,
边界宽度:2,
},
},
defaultNavigationOptions:({navigation})=>({
tabBarOnPress:({navigation,defaultHandler})=>{
navigation.poptoop();
defaultHandler();
},
}),
}
);
导出默认createAppContainer(tabScreen);
我是否遗漏了什么或申请错误