import { Colors } from '@/constants/Colors'; import { useColorScheme } from '@/hooks/useColorScheme'; import { useI18n } from '@/hooks/useI18n'; import { WeightHistoryItem } from '@/store/userSlice'; import { Ionicons } from '@expo/vector-icons'; import dayjs from 'dayjs'; import React, { useRef } from 'react'; import { Alert, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { Swipeable } from 'react-native-gesture-handler'; interface WeightRecordCardProps { record: WeightHistoryItem; onPress?: (record: WeightHistoryItem) => void; onDelete?: (recordId: string) => void; weightChange?: number; } export const WeightRecordCard: React.FC = ({ record, onPress, onDelete, weightChange = 0 }) => { const { t } = useI18n(); const swipeableRef = useRef(null); const colorScheme = useColorScheme(); const themeColors = Colors[colorScheme ?? 'light']; // 处理删除操作 const handleDelete = () => { Alert.alert( t('weightRecords.card.deleteConfirmTitle'), t('weightRecords.card.deleteConfirmMessage'), [ { text: t('weightRecords.card.cancelButton'), style: 'cancel', }, { text: t('weightRecords.card.deleteButton'), style: 'destructive', onPress: () => { const recordId = record.id || record.createdAt; onDelete?.(recordId); swipeableRef.current?.close(); }, }, ] ); }; // 渲染删除按钮 const renderRightActions = () => { return ( ); }; return ( {dayjs(record.createdAt).format('MM-DD')} {dayjs(record.createdAt).format('HH:mm')} {record.weight}{t('weightRecords.modal.unit')} {Math.abs(weightChange) > 0 && ( {Math.abs(weightChange).toFixed(1)} )} onPress?.(record)} hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }} > ); }; const styles = StyleSheet.create({ cardContainer: { shadowColor: 'rgba(30, 41, 59, 0.08)', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.12, shadowRadius: 12, elevation: 4, }, recordCard: { backgroundColor: '#ffffff', borderRadius: 24, padding: 16, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, leftContent: { flexDirection: 'row', alignItems: 'center', flex: 1, }, iconContainer: { width: 44, height: 44, borderRadius: 22, backgroundColor: '#F0F2F5', alignItems: 'center', justifyContent: 'center', marginRight: 16, }, icon: { width: 24, height: 24, tintColor: '#4F5BD5', }, textContent: { justifyContent: 'center', }, dateTimeContainer: { flexDirection: 'row', alignItems: 'center', marginBottom: 4, }, dateText: { fontSize: 14, fontWeight: '600', color: '#1c1f3a', marginRight: 8, fontFamily: 'AliBold', }, timeText: { fontSize: 12, color: '#6f7ba7', fontFamily: 'AliRegular', }, weightInfo: { flexDirection: 'row', alignItems: 'baseline', }, weightValue: { fontSize: 18, fontWeight: '700', color: '#1c1f3a', fontFamily: 'AliBold', }, unitText: { fontSize: 13, fontWeight: '500', color: '#6f7ba7', marginLeft: 2, fontFamily: 'AliRegular', }, rightContent: { flexDirection: 'row', alignItems: 'center', gap: 12, }, changeTag: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 6, paddingVertical: 2, borderRadius: 8, }, changeText: { fontSize: 11, fontWeight: '700', marginLeft: 2, fontFamily: 'AliBold', }, editButton: { padding: 4, }, deleteButton: { backgroundColor: '#FF6B6B', justifyContent: 'center', alignItems: 'center', width: 70, borderRadius: 24, marginLeft: 12, height: '100%', }, });