feat: 优化体重记录页面,使用useCallback提升加载历史记录性能,调整样式以支持深色模式
This commit is contained in:
@@ -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<WeightRecordCardProps> = ({
|
||||
weightChange = 0
|
||||
}) => {
|
||||
const swipeableRef = useRef<Swipeable>(null);
|
||||
const colorScheme = useColorScheme();
|
||||
const themeColors = Colors[colorScheme ?? 'light'];
|
||||
|
||||
// 处理删除操作
|
||||
const handleDelete = () => {
|
||||
@@ -66,10 +69,10 @@ export const WeightRecordCard: React.FC<WeightRecordCardProps> = ({
|
||||
overshootRight={false}
|
||||
>
|
||||
<View
|
||||
style={styles.recordCard}
|
||||
style={[styles.recordCard, colorScheme === 'dark' && styles.recordCardDark]}
|
||||
>
|
||||
<View style={styles.recordHeader}>
|
||||
<Text style={styles.recordDateTime}>
|
||||
<Text style={[styles.recordDateTime, { color: themeColors.textSecondary }]}>
|
||||
{dayjs(record.createdAt).format('MM月DD日 HH:mm')}
|
||||
</Text>
|
||||
<TouchableOpacity
|
||||
@@ -80,8 +83,8 @@ export const WeightRecordCard: React.FC<WeightRecordCardProps> = ({
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<View style={styles.recordContent}>
|
||||
<Text style={styles.recordWeightLabel}>体重:</Text>
|
||||
<Text style={styles.recordWeightValue}>{record.weight}kg</Text>
|
||||
<Text style={[styles.recordWeightLabel, { color: themeColors.textSecondary }]}>体重:</Text>
|
||||
<Text style={[styles.recordWeightValue, { color: themeColors.text }]}>{record.weight}kg</Text>
|
||||
{Math.abs(weightChange) > 0 && (
|
||||
<View style={[
|
||||
styles.weightChangeTag,
|
||||
@@ -108,15 +111,13 @@ export const WeightRecordCard: React.FC<WeightRecordCardProps> = ({
|
||||
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user