React-Native APP内应用角标,配合TabNavigator2018-10-26

业务系统当收到消息后,消息列表会显示具体的消息数量。之前帖子有写过,如果在app应用加消息数量,这个是对应app内显示。
同时tab导航用的是,react-navigation中的TabNavigator
具体的数量,我放在了redux中,这里测试可以写死。

角标代码

import React from "react";
import {
Text,
View,
} from "native-base";
import {
connect
} from "react-redux";
import {
NativeModules,
Platform
} from "react-native";
import JPushModule from "jpush-react-native";
const badge = NativeModules.Badge;
class NotiTabBarIcon  extends React.Component{
constructor(props) {
  super(props);
}

render() {
return (
  //判断消息数量
  this.props.counter.count>0?<View
    style={{
      position: 'absolute',
      top: 3,
      left:Platform.OS==="ios"?18:8,
      margin: -1,
      minWidth: 13,
      height: 13,
      borderRadius: 7,
      alignItems: 'center',
      justifyContent: 'center',
      backgroundColor: '#FF0000',
    }}>
      <Text style = {{
        color: '#ffffff',
        textAlign: "center",
        fontSize: 9,
      //超过99就一直显示99
      }}>{this.props.counter.count<99?this.props.counter.count:99}          </Text>
  </View>
  : null
)
}

}

const mapStateToProps = state => ({
  counter: state.counter
})

export default connect(mapStateToProps)(NotiTabBarIcon);

应用导航配置:

import NotiTabBarIcon from "./NotiTabBarIcon";
  
  //配置导航参数,显示数量用到。
  static navigationOptions = ({ navigation, screenProps }) => ({
    tabBarIcon: ({ tintColor,focused }) => (
      focused?
        <View><Icon name="navigate" style={{color:"#119DFF"}}  /><NotiTabBarIcon /></View> : <View ><Icon name="navigate" style={{color:"#C0C0C0"}}  /><NotiTabBarIcon /></View>
    )
});

最终效果

96acd9b919b5142c791145b16ff89d1f (1).gif

整套的流程我是,对接了jpush,通过监听消息,然后存储消息数量到redux,然后动态更新app应用内角标,和app外部桌面的角标。(上一篇帖子可以看到)。ios和安卓都可以用,已经测试通过。
本人QQ337241905,如果有问题,可以联系我。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 13,052评论 2 59
  • 关于更新 如果你有关注我的简书,你会发现到目前我只有两篇文章,都是我在2015年出国前写的。在那之后我就来了美国,...
    小温侯阅读 416评论 1 0
  • 和前任W先生分手后,近两年的时间里我想了很多他会放弃的理由,他太懦弱了,有新的诱惑,因为我作,他害怕结婚,命运弄人...
    芃鹿阅读 230评论 0 0
  • 总希望生活阳光明媚,这大周末一觉醒来,接到电话,瞬间把我的好心情浇灭。 小弟班主任的电话,昨天晚上小弟在和我说选专...
    小猪fly阅读 1,437评论 0 1