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, 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 ( {t('weightRecords.card.deleteButton')} ); }; return ( {dayjs(record.createdAt).format('MM[月]DD[日] HH:mm')} onPress?.(record)} > {t('weightRecords.card.weightLabel')}: {record.weight}{t('weightRecords.modal.unit')} {Math.abs(weightChange) > 0 && ( {Math.abs(weightChange).toFixed(1)} )} ); }; const styles = StyleSheet.create({ recordCard: { backgroundColor: '#ffffff', borderRadius: 16, padding: 20, marginBottom: 12, }, recordHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12, }, recordDateTime: { fontSize: 14, color: '#687076', fontWeight: '500', }, recordEditButton: { padding: 6, borderRadius: 8, backgroundColor: 'rgba(255, 149, 0, 0.1)', }, recordContent: { flexDirection: 'row', alignItems: 'center', }, recordWeightLabel: { fontSize: 16, color: '#687076', fontWeight: '500', }, recordWeightValue: { fontSize: 16, fontWeight: '600', color: '#192126', marginLeft: 4, flex: 1, }, weightChangeTag: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12, marginLeft: 12, }, weightChangeText: { fontSize: 12, fontWeight: '600', marginLeft: 2, }, deleteButton: { backgroundColor: '#EF4444', justifyContent: 'center', alignItems: 'center', width: 80, borderRadius: 16, marginBottom: 12, marginLeft: 8, }, deleteButtonText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', marginTop: 4, }, });