最终效果

在这里插入图片描述

弹窗菜单

点击右上角群聊按钮后,弹窗菜单

在这里插入图片描述

无消息

在这里插入图片描述

代码实现

app/(tabs)/message.tsx

import icon_no_collection from "@/assets/icons/icon_no_collection.webp";
import FloatMenu, {FloatMenuRef,
} from "@/modules/message/components/FloatMenu";
import Entypo from "@expo/vector-icons/Entypo";
import MaterialCommunityIcons from "@expo/vector-icons/MaterialCommunityIcons";
import { useRef } from "react";
import {FlatList,GestureResponderEvent,Image,StyleSheet,Text,TouchableOpacity,View,
} from "react-native";
import icon_comments from "../../assets/icons/icon_comments.png";
import icon_new_follow from "../../assets/icons/icon_new_follow.png";
import icon_star from "../../assets/icons/icon_star.png";
import Empty from "../../components/Empty";
export default function MessageScreen() {const ref = useRef<FloatMenuRef>(null);const messageList = [{id: 1,name: "春游起飞小组",avatarUrl:"https://img0.baidu.com/it/u=1884273668,3023246561&fm=253&app=138&f=JPEG?w=760&h=760",lastMessage: "你们到了没啊,我都等好久了",lastMessageTime: "昨天",},{id: 2,name: "手游组团菜鸡组",avatarUrl:"https://img0.baidu.com/it/u=3671371982,1586403646&fm=253&app=138&f=JPEG?w=760&h=760",lastMessage: "连跪三把,赢一把睡觉",lastMessageTime: "前天",},{id: 3,name: "抄作业小分队",avatarUrl:"https://img2.baidu.com/it/u=1858586853,494763800&fm=253&app=138&f=JPEG?w=760&h=760",lastMessage: "数学物理还没写呢",lastMessageTime: "星期四",},];const unread = {unreadFavorate: 632,newFollow: 2,comment: 0,};const renderTitle = () => {return (<View style={styles.titleLayout}><Text style={styles.titleTxt}>消息</Text><TouchableOpacitystyle={styles.groupButton}onPress={(event: GestureResponderEvent) => {const { pageY } = event.nativeEvent;ref.current?.show(pageY + 20);}}><MaterialCommunityIconsname="account-supervisor-outline"size={24}color="black"/><Text style={styles.groupTxt}>群聊</Text></TouchableOpacity></View>);};const renderItem = ({item}: {item: MessageListItem;index: number;}) => {const styles = StyleSheet.create({item: {width: "100%",height: 80,flexDirection: "row",alignItems: "center",paddingHorizontal: 16,},avatarImg: {width: 48,height: 48,borderRadius: 24,resizeMode: "cover",},contentLayout: {flex: 1,marginHorizontal: 12,},nameTxt: {fontSize: 18,color: "#333",fontWeight: "bold",},lastMessageTxt: {fontSize: 15,color: "#999",marginTop: 4,},rightLayout: {alignItems: "flex-end",},timeTxt: {fontSize: 12,color: "#999",},iconTop: {marginTop: 6,},});return (<View style={styles.item}><Image style={styles.avatarImg} source={{ uri: item.avatarUrl }} /><View style={styles.contentLayout}><Text style={styles.nameTxt}>{item.name}</Text><Text style={styles.lastMessageTxt}>{item.lastMessage}</Text></View><View style={styles.rightLayout}><Text style={styles.timeTxt}>{item.lastMessageTime}</Text><Entypostyle={styles.iconTop}name="align-top"size={18}color="grey"/></View></View>);};const UnRead = ({ count }: { count: number }) => {const styles = StyleSheet.create({txt: {position: "absolute",top: -6,right: -10,backgroundColor: "#ff2442",paddingHorizontal: 8,height: 24,borderRadius: 12,textAlign: "center",textAlignVertical: "center",fontSize: 12,color: "white",},});return <Text style={styles.txt}>{count > 99 ? "99+" : count}</Text>;};const Header = () => {const styles = StyleSheet.create({headerLayout: {paddingHorizontal: 16,flexDirection: "row",paddingVertical: 20,},headerItem: {flex: 1,alignItems: "center",},itemImg: {width: 60,height: 60,resizeMode: "contain",},itemTxt: {fontSize: 16,color: "#333",marginTop: 8,},});return (<View style={styles.headerLayout}><View style={styles.headerItem}><View><Image style={styles.itemImg} source={icon_star} />{!!unread?.unreadFavorate && (<UnRead count={unread?.unreadFavorate} />)}</View><Text style={styles.itemTxt}>赞和收藏</Text></View><View style={styles.headerItem}><View><Image style={styles.itemImg} source={icon_new_follow} />{!!unread?.newFollow && <UnRead count={unread?.newFollow} />}</View><Text style={styles.itemTxt}>新增关注</Text></View><View style={styles.headerItem}><View><Image style={styles.itemImg} source={icon_comments} />{!!unread?.comment && <UnRead count={unread?.comment} />}</View><Text style={styles.itemTxt}>评论和@</Text></View></View>);};return (<View style={styles.page}>{renderTitle()}<FlatListstyle={{ flex: 1 }}data={messageList}extraData={[unread]}keyExtractor={(item) => `${item.id}`}renderItem={renderItem}ListHeaderComponent={<Header />}ListEmptyComponent={<Empty icon={icon_no_collection} tips="暂无消息" />}/><FloatMenu ref={ref} /></View>);
}
const styles = StyleSheet.create({page: {width: "100%",height: "100%",backgroundColor: "white",},groupTxt: {fontSize: 14,color: "#333",marginLeft: 6,},titleLayout: {width: "100%",height: 48,flexDirection: "row",alignItems: "center",justifyContent: "center",},titleTxt: {fontSize: 18,color: "#333",},groupButton: {height: "100%",flexDirection: "row",alignItems: "center",position: "absolute",right: 16,},
});

相关组件

弹窗菜单

modules/message/components/FloatMenu.tsx

import MaterialCommunityIcons from "@expo/vector-icons/MaterialCommunityIcons";
import React, { forwardRef, useImperativeHandle, useState } from "react";
import { Modal, StyleSheet, Text, TouchableOpacity, View } from "react-native";
export interface FloatMenuRef {show: (pageY: number) => void;hide: () => void;
}
// eslint-disable-next-line react/display-name
export default forwardRef((props: any, ref) => {const [visible, setVisible] = useState<boolean>(false);const [y, setY] = useState<number>(100);const show = (pageY: number) => {setY(pageY);setVisible(true);};const hide = () => {setVisible(false);};useImperativeHandle(ref, () => {return {show,hide,};});const renderMenus = () => {return (<View style={[styles.content, { top: y }]}><TouchableOpacity style={styles.menuItem}><MaterialCommunityIconsname="account-group-outline"size={24}color="black"/><Text style={styles.menuTxt}>群聊广场</Text></TouchableOpacity><View style={styles.line} /><TouchableOpacity style={styles.menuItem}><MaterialCommunityIconsname="chat-plus-outline"size={24}color="black"/><Text style={styles.menuTxt}>创建群聊</Text></TouchableOpacity></View>);};return (<Modaltransparent={true}visible={visible}statusBarTranslucent={true}animationType="fade"onRequestClose={hide}><TouchableOpacity style={styles.root} onPress={hide}>{renderMenus()}</TouchableOpacity></Modal>);
});
const styles = StyleSheet.create({root: {width: "100%",height: "100%",backgroundColor: "#00000040",},content: {width: 170,backgroundColor: "white",borderRadius: 16,position: "absolute",right: 10,},menuItem: {width: "100%",flexDirection: "row",alignItems: "center",height: 56,paddingLeft: 20,},menuIcon: {width: 28,height: 28,},menuTxt: {fontSize: 18,color: "#333",marginLeft: 10,},line: {marginLeft: 20,marginRight: 16,height: 1,backgroundColor: "#eee",},
});

空白页

components/Empty.tsx

import React from "react";
import { Image, StyleSheet, Text, View } from "react-native";
type Props = {icon: number;tips: string;
};
// eslint-disable-next-line react/display-name
export default ({ icon, tips }: Props) => {return (<View style={styles.root}><Image style={styles.icon} source={icon} /><Text style={styles.tipsTxt}>{tips}</Text></View>);
};
const styles = StyleSheet.create({root: {alignItems: "center",paddingTop: 120,},icon: {width: 96,height: 96,resizeMode: "contain",},tipsTxt: {fontSize: 14,color: "#bbb",marginTop: 16,},
});

图片素材

assets/icons/icon_no_collection.webp

在这里插入图片描述

assets/icons/icon_star.png

在这里插入图片描述

assets/icons/icon_comments.png

在这里插入图片描述

assets/icons/icon_new_follow.png

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/news/913814.shtml
繁体地址,请注明出处:http://hk.pswp.cn/news/913814.shtml
英文地址,请注明出处:http://en.pswp.cn/news/913814.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Jenkins详细教程 - 从入门到精通

目录 1. 什么是Jenkins 1.1 简单理解 1.2 技术定义 1.3 核心特点 2. 为什么需要Jenkins 2.1 传统开发的痛点 手工发布的问题 真实场景举例 2.2 Jenkins的解决方案 自动化CI/CD流程 3. 核心概念解析 3.1 Job(任务) Job示例 3.2 Build(构建) 3.3 Pipeline(流水…

bash 判断 /opt/wslibs-cuda11.8 是否为软连接, 如果是,获取连接目的目录并自动创建

以下是实现该功能的 Bash 脚本&#xff1a; bash #!/bin/bash LINK_PATH“/opt/wslibs-cuda11.8” 检查是否为软链接 if [ -L "KaTeX parse error: Expected EOF, got # at position 24: …H" ]; then#̲ 获取软链接的绝对目标路径…(readlink -f “$LINK_PATH”) # …

【性能测试】jmeter+Linux环境部署和分布式压测,一篇打通...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 1、linux获取动态…

Java 17 新特性笔记

Java 17 是一个 长期支持版本&#xff08;LTS&#xff09;&#xff0c;于 2021 年 9 月发布&#xff0c;是继 Java 11 之后的重要里程碑。它整合了 Java 12~16 的众多特性&#xff0c;并引入新的语言增强、JDK API 改进、性能优化和安全增强。 Java 17 版本信息 发布时间&…

WWDC 25 风云再起:SwiftUI 7 Charts 心法从 2D 到 3D 的华丽蜕变

概述 在 iOS 开发这个波谲云诡的江湖中&#xff0c;SwiftUI 可谓是一位后起之秀&#xff0c;以其简洁明快的招式迅速在 UI 框架领域中崭露头角。 而其中的 Charts 框架&#xff0c;更是如同江湖中的 “数据可视化宝典”那样&#xff0c;让各位秃头少侠们能够轻松将复杂的数据转…

Vue+Element Plus 中按回车刷新页面问题排查与解决

VueElement Plus 中按回车刷新页面问题排查与解决原因分析解决方案方法一&#xff1a;阻止默认行为 submit.prevent方法二&#xff1a;只监听回车并触发搜索最终推荐写法如下&#xff1a;在使用 Vue 3 Element Plus 开发后台系统时&#xff0c;我们常常会通过 搭配 实现搜索功…

x86汇编语言入门基础(三)汇编指令篇3 位移运算

位移运算指令&#xff1a;SHL逻辑移位&#xff0c;SAR算术移位&#xff0c; ROR循环右移 1. SHL 逻辑移位 Shift Left, SHL代表向左移位&#xff0c;SHR代表向右移位 指令格式&#xff1a;shl op1, op2 目的操作数 op1&#xff1a;寄存器/内存地址源操作数 op2&#xff1a;寄…

Java-69 深入浅出 RPC 单体架构 垂直架构 分布式架构 微服务架构

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; &#x1f680; AI篇持续更新中&#xff01;&#xff08;长期更新&#xff09; AI炼丹日志-29 - 字节跳动 DeerFlow 深度研究框斜体样式架 私有…

Android 如何阻止应用自升级

问题背景 1.打开PlayStore,然后登陆账户 2.退出应用过几分钟后,应用会自动更新到新版本 3.再次打开应用,问题即可复现 一联网进入playStore应用并且登录谷歌账号,退出几分钟,在进入,发现应用版本号更新了,应用进行了自我升级,关键是升级之后谷歌商店就用不了了,就…

Docker-构建镜像并实现LNMP架构

一、搭建LNMP基础配置1、制作Nginx镜像制作dockerfilevim dockerfileFROM centos:7 RUN rm -rf /etc/yum.repos.d/* RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo RUN yum clean all RUN yum makecache RUN yum -y install z…

Python之--基本知识

基本输出语法结构: print(输出内容)print()函数完整的语法格出: print (value,...,sep,end\n,fileNone)只有字符串可以用连接基本输入语法结构: xinput(提示文字’)注意事项: 无论输入的数据是什么 x 的数据类型都是字符串类型示例&#xff1a;name input("Enter your na…

VS CodeC51 单片机开发环境搭建

文章目录前言1.安装插件2.创建EIDE项目&#xff08;51单片机&#xff09;3.配置工具链&#xff08;第一次使用需要配置&#xff09;4.编译与下载5.项目文件简介与串口调试工具6.推荐插件7.打包模板与导出模板8.51单片机串口无法识别问题前言 需要安装keil c51版本需要配置好C/…

国密算法(SM2/SM3/SM4)

文章目录国密算法&#xff08;SM2/SM3/SM4&#xff09;详解&#xff1a;从性能对比到Java手机号安全处理实战一、 国密核心算法简介二、 性能深度对比三、 Java实战&#xff1a;手机号的安全处理方案一&#xff1a;使用SM3哈希存储&#xff08;推荐用于验证场景&#xff09;方案…

从前端转go开发的学习路线

从前端开发转向 Go&#xff08;Golang&#xff09;后端开发&#xff0c;是一个非常可行也很实用的方向&#xff0c;特别是在做 高性能微服务、分布式系统、云原生&#xff08;如Kubernetes&#xff09; 等方面。以下是一份适合你&#xff08;有多年开发经验的前端开发者&#x…

node或浏览器上传文件到阿里云OSS

阿里云配置 进入阿里云OSS Bucket 列表的某个 Bucket 仓库下&#xff0c;点击访问控制 RAM 创建用户 勾上 创建 AccessKey ID 和 AccessKey Secret 复制 AccessKey 信息 用文档保存 创建角色 选择云账号 复制 ARN 用文档保存&#xff0c;然后 新增权限 搜索 oss 选择 AliyunOSS…

26考研物理复试面试常见问答问题汇总,物理专业保研推免夏令营面试问题汇总,物理本科知识专业面试最全攻略!

还在为物理考研复试面试发愁&#xff1f;还在为物理招聘的专业面试抓狂&#xff1f;还在为即将到来的物理夏令营面试不知从何下手、翻遍了厚厚的教材却抓不住重点&#xff1f;别慌&#xff0c;接下来我会从「考研的物理复试经历」「物理面试攻略」「物理面试基础问答题汇总很全…

(5)机器学习小白入门 YOLOv:数据需求与图像不足应对策略

(1)机器学习小白入门YOLOv &#xff1a;从概念到实践 (2)机器学习小白入门 YOLOv&#xff1a;从模块优化到工程部署 (3)机器学习小白入门 YOLOv&#xff1a; 解锁图片分类新技能 (4)机器学习小白入门YOLOv &#xff1a;图片标注实操手册 (5)机器学习小白入门 YOLOv&#xff1a;…

百年制造名企,三菱重工引领“智”造新范式

日前&#xff0c;由深圳软件协会指导、法大大和信息侠联合出品的《制造行业合同数智化升级白皮书》&#xff08;以下简称“白皮书”&#xff09;正式发布&#xff0c;并首次提出 “电子签法律AI” 双轮驱动模型。在制造行业面临供应链协同、合规风控及全球化出海等多重挑战的当…

【学习笔记】计算机操作系统(七)—— 文件管理

第七章 文件管理 文章目录第七章 文件管理7.1 文件和文件系统7.1.1 数据项、记录和文件7.1.2 文件名和类型7.1.3 文件系统的层次结构7.1.4 文件操作7.2 文件的逻辑结构7.2.1 文件逻辑结构的类型7.2.2 顺序文件(Sequential File)7.2.3 记录寻址7.2.4 索引文件(Index File)7.2.5 …

基于PyQt5与深度学习的可视化水果识别系统(集成CNN, MobileNetV2, VGG16)

一、项目概述 大家好&#xff01;今天我将分享一个我近期完成的深度学习项目——一个功能强大的、带图形化界面&#xff08;GUI&#xff09;的水果识别系统。该系统不仅能识别静态图片中的水果&#xff0c;还集成了模型训练、评估、数据增强等功能于一体&#xff0c;为深度学习…