当前位置: 首页 > news >正文

鸿蒙开发融云demo消息未读数

鸿蒙开发融云demo消息未读数

跟着我一步步搭建带界面的融云demo,这次是要显示未读数,未读数有两个,一个是消息列表的未读数,一个是主页消息tab上的未读数。

一、消息列表的未读数

先看下效果图:

在这里插入图片描述
关键代码如下:

if (this.chatItem.unreadMessageCount > 0 || this.customUnReadCount > 0) { // 红点消息大于0条时渲染红点Row() {Text(this.chatItem.unreadMessageCount > 0?`${this.chatItem.unreadMessageCount}`:`${this.customUnReadCount}`).borderRadius($r('app.integer.layout_8')).constraintSize({minWidth: $r('app.integer.opt_layout_chat_view_red_dot_width')}).height($r('app.integer.opt_layout_chat_view_red_dot_height')).backgroundColor($r('app.color.color_red')).fontSize($r('app.integer.text_font_10')).textAlign(TextAlign.Center).fontColor(Color.White)}.alignItems(VerticalAlign.Center).justifyContent(FlexAlign.Center).borderRadius($r('app.integer.layout_10')).margin({ top: $r('app.integer.layout_minus_8'), left: $r('app.integer.layout_24') }).constraintSize({minWidth: $r('app.integer.opt_layout_chat_view_red_dot_container_width')}).height($r('app.integer.opt_layout_chat_view_red_dot_container_height')).backgroundColor(Color.White).alignRules({top: { anchor: '__container__', align: VerticalAlign.Top },left: { anchor: '__container__', align: HorizontalAlign.Start }}).opacity((this.chatItem.unreadMessageCount > 0 || this.customUnReadCount > 0) ? 1 : 0).id('badge')}
二、主页消息tab的未读数:

先看下效果图:
在这里插入图片描述
关键代码如下:

public static getPrivateUnReadCount(unreadCountCallback: (unreadCount: number) => void) {let unreadCount = 0let conTypeList = new List<ConversationType>();conTypeList.add(ConversationType.Private);let isContainBlocked = false;IMEngine.getInstance().getUnreadCountByTypes(conTypeList, isContainBlocked).then(result => {if (EngineError.Success !== result.code) {// 获取未读数失败return;}if (!result.data) {// 未读数为 nullreturn;}unreadCount = result.data as number;unreadCountCallback(unreadCount )});}
@BuilderTabBottom(item: TabItem, index: number) {Column() {// 发现在TabBottom传值改变不了,就用要显示未读数加上位置判断,用if else显示组件,这样不用算badge的size// 规则:字符串’-1‘代表的是红点,其他字符串数字为数字红点if ((isNotEmptyString(this.unreadNumHome) && index === 0) ||(isNotEmptyString(this.unreadNumMsg) && index === 1) ||(isNotEmptyString(this.unreadNumMine) && index === 2)) {Badge({value: index === 0 ? (this.unreadNumHome === '-1' ? '' : this.unreadNumHome) :index === 1 ? (this.unreadNumMsg === '-1' ? '' : this.unreadNumMsg) :(this.unreadNumMine === '-1' ? '' : this.unreadNumMine), // 设置 badge 的显示文本position: BadgePosition.RightTop, // 设置 badge 显示在右上角style: index === 0 || index === 1 ? { badgeColor: $r('app.color.color_red') } :{ badgeSize: 9, badgeColor: $r('app.color.color_red') }// 设置 badge 的显示样式,首页和消息不用限制大小,让它自适应}) {Column() {Image(this.selectedIndex === index ? item.imageActivated : item.imageOriginal).height($r('app.float.tab_image_size')).width($r('app.float.tab_image_size'))}.padding({ left: 10, right: 10, })}.margin({ top: 5, bottom: 5 })} else {Column() {Image(this.selectedIndex === index ? item.imageActivated : item.imageOriginal).height($r('app.float.tab_image_size')).width($r('app.float.tab_image_size'))}.padding({ left: 10, right: 10, }).margin({ top: 5, bottom: 5 })}Text(item.title).fontSize($r('app.float.tab_text_font_size')).fontWeight(500).fontColor(this.selectedIndex === index ? $r('app.color.color_main') : Color.White).textAlign(TextAlign.Center).margin({bottom: $r('app.float.tab_text_margin_bottom')})}.justifyContent(FlexAlign.Center).height('100%').width('100%').backgroundColor($r("app.color.color_black")).onClick(() => {this.selectedIndex = index})}
整个鸿蒙融云demo项目结构图:

在这里插入图片描述
有问题或者需要完整源码的私信我

http://www.lryc.cn/news/468343.html

相关文章:

  • 非对称加密算法(RSA):原理、应用与代码实现
  • docker部署SQL审核平台Archery
  • ceph 删除rbd 锁的命令
  • MySQL【知识改变命运】01
  • 苍穹外卖 Maven依赖配置
  • Lucas带你手撕机器学习——SVM支持向量机
  • 将后端返回的网络url转成blob对象,实现pdf预览
  • 民峰金融智能交易模型的应用与未来趋势
  • 文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑负荷时空迁移的5G基站与配电网协同优化运行 》
  • 数据结构中的堆(Heap)
  • Linux误删文件找回
  • 深入计算机语言之C++:类与对象(中)
  • 51单片机快速入门之 IIC I2C通信
  • 腾讯推出ima.copilot智能工作台产品 由混元大模型提供技术支持
  • 1024是什么日子
  • 驱动开发系列20 - Linux Graphics Xorg-server 介绍
  • 晶台推出SOP5封装的高速光耦KLM45X,提供1MBit/s超快速率
  • 软物质流变探究:从宏观微观差异,到水凝胶界面特性
  • Axure中继器单选、多选和重置
  • 微软公司用没有使用证据的商标申请驰名商标,该怎么维权?
  • 学习分布式系统我来助你!【基本知识、基础理论、设计模式、应用场景、工程应用、缓存等全包含!】
  • ubuntu查看系统版本命令
  • 使用yield压平嵌套字典有多简单?
  • express中使用morgan打印请求数据日志文件,按日期分割
  • 干货 | 2024 AI+智慧城市安全解决方案白皮书(免费下载)
  • 超越 React Query:探索更高效的数据请求策略
  • Scala trait
  • AI大法之C语言哈希表算法比较两个文件去重
  • Scala 提取器(Extractor)
  • 【主机漏洞扫描常见修复方案】:Tomcat安全(机房对外Web服务扫描)