如何在收到新的订阅时更新导航标题中的计数?

问题描述 投票:0回答:1

我正在使用graphql订阅来获取更新时创建新用户,一切正常,我收到更新,但我无法从渲染方法更新导航标题中的通知计数。

class ContactsList extends Component {

static navigationOptions = ({ navigation }) => {
    return {

        headerRight: (
            <View style={{ flexDirection: 'row' }}>
                <View style={{ marginEnd: 5 }}>
                    <Icon.Button
                        name="bell"
                        backgroundColor="#3b5998"
                        onPress={() => alert('Bell Pressed!!')}>

                    **//i want update the count here when new contact is created** 
                    </Icon.Button>
                </View>
            </View>

        ),
    };
};
render() {
    return (
        <View>
            <Subscription
                subscription={NEW_NOTIFICATION_SUBSCRIPTION}
                variables={{ token: this.state.golbalDashboardToken }} >
                {({ data, loading }) => {
                    if (loading) {
                        // alert('Loading Subcription');
                        return <Text>Loading Subscription</Text>
                    }
                    if (data) {

                        **// when new contact is created i will receive the data her**


                    }

                }
                }  
            </Subscription>
        </View
      );

}
}

创建新用户时,我将在Subscription选项卡中收到数据

react-native graphql react-navigation
1个回答
1
投票

试试这个:

 if (data && data !== oldData) {

     **// when new contact is created i will receive the data her**
     this.props.navigation.setParams({ data }); // << this
 }

在navigationOptions中

<Icon.Button
          name="bell"
          backgroundColor="#3b5998"
          onPress={() => alert('Bell Pressed!!')}>

          **//i want update the count here when new contact is created**
          const newData = navigation.getParam('data'); // this
 </Icon.Button>
© www.soinside.com 2019 - 2024. All rights reserved.