import React from 'react' import { View, Text, TouchableOpacity, StyleSheet } from 'react-native' import { LinearGradient } from 'expo-linear-gradient' // Types export type MessageType = 'ACTIVITY' | 'SYSTEM' | 'BILLING' | undefined export interface TabItem { key: string label: string type: MessageType } export interface MessageTabBarProps { activeTab: MessageType onTabChange: (type: MessageType) => void unreadCounts?: { all?: number activity?: number system?: number billing?: number } } // Constants export const TAB_ITEMS: TabItem[] = [ { key: 'all', label: '全部', type: undefined }, { key: 'activity', label: '互动', type: 'ACTIVITY' }, { key: 'system', label: '系统', type: 'SYSTEM' }, { key: 'billing', label: '账单', type: 'BILLING' }, ] // Helper function to format badge count const formatBadgeCount = (count: number): string => { if (count > 99) { return '99+' } return String(count) } // Helper function to get unread count for a tab const getUnreadCount = ( key: string, unreadCounts?: MessageTabBarProps['unreadCounts'] ): number | undefined => { if (!unreadCounts) return undefined switch (key) { case 'all': return unreadCounts.all case 'activity': return unreadCounts.activity case 'system': return unreadCounts.system case 'billing': return unreadCounts.billing default: return undefined } } export const MessageTabBar: React.FC = ({ activeTab, onTabChange, unreadCounts, }) => { return ( {TAB_ITEMS.map((tab) => { const isActive = activeTab === tab.type const unreadCount = getUnreadCount(tab.key, unreadCounts) const showBadge = unreadCount !== undefined && unreadCount > 0 return ( onTabChange(tab.type)} activeOpacity={0.7} > {tab.label} {showBadge && ( {formatBadgeCount(unreadCount)} )} {isActive && ( )} ) })} ) } const styles = StyleSheet.create({ container: { flexDirection: 'row', backgroundColor: '#090A0B', paddingHorizontal: 16, paddingTop: 12, }, tabItem: { marginRight: 24, paddingBottom: 8, alignItems: 'center', }, tabContent: { flexDirection: 'row', alignItems: 'center', }, tabLabel: { fontSize: 16, fontWeight: '500', }, tabLabelActive: { color: '#FFFFFF', }, tabLabelInactive: { color: '#8A8A8A', }, activeIndicator: { height: 2, width: '100%', marginTop: 6, borderRadius: 1, }, badge: { backgroundColor: '#FF3B30', borderRadius: 10, minWidth: 18, height: 18, paddingHorizontal: 5, marginLeft: 4, justifyContent: 'center', alignItems: 'center', }, badgeText: { color: '#FFFFFF', fontSize: 11, fontWeight: '600', }, })