ReactNative【實戰系列教程】我的小紅書 7 -- 消息(含彈窗菜單,右上角角標,空白頁等)

最終效果

在這里插入圖片描述

彈窗菜單

點擊右上角群聊按鈕后,彈窗菜單

在這里插入圖片描述

無消息

在這里插入圖片描述

代碼實現

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;為深度學習…