diff --git a/app/weight-records.tsx b/app/weight-records.tsx index 0c67c49..0b70c40 100644 --- a/app/weight-records.tsx +++ b/app/weight-records.tsx @@ -9,7 +9,7 @@ import { Ionicons } from '@expo/vector-icons'; import dayjs from 'dayjs'; import { LinearGradient } from 'expo-linear-gradient'; import { router } from 'expo-router'; -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { Alert, Modal, @@ -34,18 +34,17 @@ export default function WeightRecordsPage() { console.log('userProfile:', userProfile); - - useEffect(() => { - loadWeightHistory(); - }, []); - - const loadWeightHistory = async () => { + const loadWeightHistory = useCallback(async () => { try { await dispatch(fetchWeightHistory() as any); } catch (error) { console.error('加载体重历史失败:', error); } - }; + }, [dispatch]); + + useEffect(() => { + loadWeightHistory(); + }, [loadWeightHistory]); const handleGoBack = () => { router.back(); @@ -465,7 +464,7 @@ const styles = StyleSheet.create({ backgroundColor: 'rgba(255, 149, 0, 0.1)', }, monthContainer: { - marginBottom: 16, + marginBottom: 20, }, monthHeaderCard: { backgroundColor: '#FFFFFF', diff --git a/components/weight/WeightRecordCard.tsx b/components/weight/WeightRecordCard.tsx index 239f033..e913979 100644 --- a/components/weight/WeightRecordCard.tsx +++ b/components/weight/WeightRecordCard.tsx @@ -1,4 +1,5 @@ import { Colors } from '@/constants/Colors'; +import { useColorScheme } from '@/hooks/useColorScheme'; import { WeightHistoryItem } from '@/store/userSlice'; import { Ionicons } from '@expo/vector-icons'; import dayjs from 'dayjs'; @@ -20,6 +21,8 @@ export const WeightRecordCard: React.FC = ({ weightChange = 0 }) => { const swipeableRef = useRef(null); + const colorScheme = useColorScheme(); + const themeColors = Colors[colorScheme ?? 'light']; // 处理删除操作 const handleDelete = () => { @@ -66,10 +69,10 @@ export const WeightRecordCard: React.FC = ({ overshootRight={false} > - + {dayjs(record.createdAt).format('MM月DD日 HH:mm')} = ({ - 体重: - {record.weight}kg + 体重: + {record.weight}kg {Math.abs(weightChange) > 0 && ( = ({ const styles = StyleSheet.create({ recordCard: { - backgroundColor: '#FFFFFF', + backgroundColor: '#F0F0F0', borderRadius: 16, padding: 20, marginBottom: 12, - shadowColor: '#000', - shadowOffset: { width: 0, height: 1 }, - shadowOpacity: 0.06, - shadowRadius: 8, - elevation: 2, + }, + recordCardDark: { + backgroundColor: '#1F2937', }, recordHeader: { flexDirection: 'row',