【发布时间】:2020-03-27 19:06:32
【问题描述】:
我使用 createBottomTabNavigator 作为标签栏。并且在通知的标签栏中,计数由自定义构建徽章显示。问题是每当更新通知时,标签栏中图标的计数不会改变。我必须导航单击任何其他项目以更新计数。我使用 AsyncStorage 将计数存储在通知组件中,并在客户组件中获取该计数,该组件在 tabnavigator 中调用。
class TabNotificationCount extends Component {
constructor(props) {
super(props);
this.state = {
focus: false,
notificationCount: 0,
}
}
componentWillReceiveProps(nextProps) {
this.setState({ focus: nextProps.isfocus })
AsyncStorage.getItem('@count', (err, value) => {
this.setState({ notificationCount: value })
console.log("value-notification", this.state.notificationCount);
})
}
render() {
const { notificationCount } = this.state;
const icon = this.state.focus ? require('../../../images/bell-active.png') : require('../../../images/bell-active.png');
return (
<View style={{ flexDirection: 'row' }}>
<Image source={icon} style={{ width: 22, height: 22, }} />
<Text style={{ position: 'absolute', top: -10, right: -15, borderRadius: 10, backgroundColor: 'red', color: '#fff', }}>{" " + notificationCount + " "}</Text>
</View>
);
}
}
【问题讨论】:
-
分享你的代码
-
@DevAS 请看一下代码。
-
是否可以使用 {} 标签共享您的代码?很难读。
-
@Gyepesto 不幸的是我无法访问我的电脑,所以我通过手机上传代码,因此对齐不正确。
-
@Gyepesto 不幸的是我无法访问我的电脑,所以我通过手机上传代码,因此对齐不正确。
标签: react-native navigation react-native-navigation tabnavigator