feat: 增强食物库功能,支持自定义食物的创建与删除,优化用户体验

This commit is contained in:
2025-08-29 21:03:45 +08:00
parent e9b593a07e
commit 3fdd2acaf2
8 changed files with 301 additions and 213 deletions

View File

@@ -6,7 +6,6 @@ import dayjs from 'dayjs';
import React, { useMemo, useRef, useState } from 'react';
import { Alert, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { Swipeable } from 'react-native-gesture-handler';
import Popover from 'react-native-popover-view';
export type NutritionRecordCardProps = {
record: DietRecord;
@@ -46,7 +45,6 @@ export function NutritionRecordCard({
const surfaceColor = useThemeColor({}, 'surface');
const textColor = useThemeColor({}, 'text');
const textSecondaryColor = useThemeColor({}, 'textSecondary');
const primaryColor = useThemeColor({}, 'primary');
// Popover 状态管理
const [showPopover, setShowPopover] = useState(false);
@@ -80,7 +78,6 @@ export function NutritionRecordCard({
}, [record]);
const mealTypeColor = MEAL_TYPE_COLORS[record.mealType];
const mealTypeIcon = MEAL_TYPE_ICONS[record.mealType];
const mealTypeLabel = MEAL_TYPE_LABELS[record.mealType];
// 处理删除操作
@@ -182,8 +179,8 @@ export function NutritionRecordCard({
</View>
{/* 餐次标签 */}
<View style={[styles.mealTypeBadge, { backgroundColor: mealTypeColor }]}>
<ThemedText style={[styles.mealTypeText, { color: '#FFFFFF' }]}>
<View style={[styles.mealTypeBadge]}>
<ThemedText style={[styles.mealTypeText, { color: mealTypeColor }]}>
{mealTypeLabel}
</ThemedText>
</View>
@@ -201,29 +198,6 @@ export function NutritionRecordCard({
</TouchableOpacity>
</Swipeable>
{/* Popover for more options */}
<Popover
from={popoverRef}
isVisible={showPopover}
onRequestClose={() => setShowPopover(false)}
popoverStyle={styles.popoverContainer}
backgroundStyle={styles.popoverBackground}
>
<View style={styles.popoverContent}>
<TouchableOpacity
style={styles.popoverItem}
onPress={() => {
setShowPopover(false);
onDelete?.();
}}
>
<Ionicons name="trash-outline" size={20} color="#FF3B30" />
<ThemedText style={[styles.popoverText, { color: '#FF3B30' }]}>
</ThemedText>
</TouchableOpacity>
</View>
</Popover>
</View>
);
}
@@ -245,8 +219,6 @@ const styles = StyleSheet.create({
backgroundColor: '#FFFFFF',
borderRadius: 12,
padding: 12,
},
mainContent: {
flex: 1,
@@ -276,13 +248,13 @@ const styles = StyleSheet.create({
},
foodName: {
fontSize: 15,
fontSize: 14,
fontWeight: '600',
color: '#333333',
marginBottom: 2,
marginTop: 2,
},
mealTime: {
fontSize: 12,
fontSize: 10,
fontWeight: '400',
color: '#999999',
},
@@ -324,6 +296,7 @@ const styles = StyleSheet.create({
caloriesText: {
fontSize: 12,
color: '#473c3cff',
fontWeight: '500',
},
mealTypeBadge: {
paddingHorizontal: 8,