This commit is contained in:
imeepos
2026-01-29 15:51:39 +08:00
parent 6279752f23
commit 7e6de68891
16 changed files with 2106 additions and 456 deletions

View File

@@ -1,11 +1,13 @@
import { Tabs } from 'expo-router'
import React from 'react'
import React, { useEffect } from 'react'
import { StyleSheet, View, Text, Platform } from 'react-native'
import { LinearGradient } from 'expo-linear-gradient'
import { useTranslation } from 'react-i18next'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { HomeIcon, MessageIcon, MyIcon, VideoIcon } from '@/components/icon'
import { useMessageUnreadCount } from '@/hooks/use-message-unread-count'
import { useAnnouncementUnreadCount } from '@/hooks/use-announcement-unread-count'
const TAB_BAR_HEIGHT = 80
@@ -15,6 +17,19 @@ export default function TabLayout() {
// Android 不需要额外的底部安全区域iOS 和 Web 需要
const bottomInset = Platform.OS === 'android' ? 0 : insets.bottom
// 获取未读消息数和公告数
const { data: messageData, refetch: refetchMessages } = useMessageUnreadCount()
const { data: announcementData, refetch: refetchAnnouncements } = useAnnouncementUnreadCount()
// 计算总未读数
const totalUnreadCount = (messageData?.count || 0) + (announcementData?.count || 0)
// 组件挂载时获取未读数
useEffect(() => {
refetchMessages()
refetchAnnouncements()
}, [])
return (
<Tabs
screenOptions={{
@@ -96,14 +111,22 @@ export default function TabLayout() {
tabBarIcon: ({ focused }: { focused: boolean }) => {
if (focused) {
return (
<LinearGradient colors={['#9966FF', '#FF6699', '#FF9966']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={styles.iconContainer}>
<MessageIcon />
</LinearGradient>
<View>
<LinearGradient colors={['#9966FF', '#FF6699', '#FF9966']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={styles.iconContainer}>
<MessageIcon />
</LinearGradient>
{totalUnreadCount > 0 && (
<View testID="message-unread-badge" style={styles.unreadBadge} />
)}
</View>
)
}
return (
<View style={{ opacity: focused ? 1 : 0.6 }}>
<MessageIcon />
{totalUnreadCount > 0 && (
<View testID="message-unread-badge" style={styles.unreadBadge} />
)}
</View>
)
},
@@ -147,4 +170,13 @@ const styles = StyleSheet.create({
color: '#FFFFFF',
textAlign: 'center',
},
unreadBadge: {
position: 'absolute',
top: 0,
right: 0,
width: 8,
height: 8,
borderRadius: 4,
backgroundColor: '#00FF66',
},
})