From 2df747109c33535f1494f2e113a8a96067c75478 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Fri, 5 Sep 2025 23:01:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BD=93=E9=87=8D?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?useCallback=E6=8F=90=E5=8D=87=E5=8A=A0=E8=BD=BD=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95=E6=80=A7=E8=83=BD=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=A0=B7=E5=BC=8F=E4=BB=A5=E6=94=AF=E6=8C=81=E6=B7=B1?= =?UTF-8?q?=E8=89=B2=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/weight-records.tsx | 17 ++++++++--------- components/weight/WeightRecordCard.tsx | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) 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',