- 集成 @react-native-voice/voice 实现中文语音识别,支持“一句话记录”餐食 - 新增语音录制页面,含波形动画、音量反馈与识别结果确认 - FloatingFoodOverlay 新增语音入口,打通拍照/库/语音三种记录方式 - 添加麦克风与语音识别权限描述(iOS Info.plist 与 Android manifest) - 实现开发者模式:连续三次点击用户名激活,含日志查看、导出与清除 - 新增 logger 工具类,统一日志存储(AsyncStorage)与按级别输出 - 重构 BackgroundTaskManager 为单例并支持 Promise 初始化,避免重复注册 - 移除 sleep-detail 多余渐变背景,改用 ThemedView 统一主题 - 新增通用 haptic 反馈函数,支持多种震动类型(iOS only) - 升级 expo-background-task、expo-notifications、expo-task-manager 至兼容版本
204 lines
4.5 KiB
TypeScript
204 lines
4.5 KiB
TypeScript
import { ROUTES } from '@/constants/Routes';
|
|
import { Ionicons } from '@expo/vector-icons';
|
|
import { BlurView } from 'expo-blur';
|
|
import { useRouter } from 'expo-router';
|
|
import React from 'react';
|
|
import {
|
|
Modal,
|
|
StyleSheet,
|
|
Text,
|
|
TouchableOpacity,
|
|
View,
|
|
} from 'react-native';
|
|
|
|
interface FloatingFoodOverlayProps {
|
|
visible: boolean;
|
|
onClose: () => void;
|
|
mealType?: string;
|
|
}
|
|
|
|
export function FloatingFoodOverlay({ visible, onClose, mealType = 'dinner' }: FloatingFoodOverlayProps) {
|
|
const router = useRouter();
|
|
|
|
const handleFoodLibrary = () => {
|
|
onClose();
|
|
router.push(`${ROUTES.FOOD_LIBRARY}?mealType=${mealType}`);
|
|
};
|
|
|
|
const handlePhotoRecognition = () => {
|
|
onClose();
|
|
router.push(`/food/camera?mealType=${mealType}`);
|
|
};
|
|
|
|
const handleVoiceRecord = () => {
|
|
onClose();
|
|
router.push(`${ROUTES.VOICE_RECORD}?mealType=${mealType}`);
|
|
};
|
|
|
|
const menuItems = [
|
|
{
|
|
id: 'scan',
|
|
title: 'AI识别',
|
|
icon: '📷',
|
|
backgroundColor: '#4FC3F7',
|
|
onPress: handlePhotoRecognition,
|
|
},
|
|
{
|
|
id: 'food-library',
|
|
title: '食物库',
|
|
icon: '🍎',
|
|
backgroundColor: '#FF9500',
|
|
onPress: handleFoodLibrary,
|
|
},
|
|
{
|
|
id: 'voice-record',
|
|
title: '一句话记录',
|
|
icon: '🎤',
|
|
backgroundColor: '#7B68EE',
|
|
onPress: handleVoiceRecord,
|
|
},
|
|
];
|
|
|
|
return (
|
|
<Modal
|
|
visible={visible}
|
|
|
|
transparent={true}
|
|
animationType="fade"
|
|
onRequestClose={onClose}
|
|
|
|
>
|
|
<BlurView intensity={20} tint="dark" style={styles.overlay}>
|
|
<TouchableOpacity
|
|
style={styles.backdrop}
|
|
activeOpacity={1}
|
|
onPress={onClose}
|
|
/>
|
|
|
|
<View style={styles.container}>
|
|
<BlurView intensity={80} tint="light" style={styles.blurContainer}>
|
|
<View style={styles.header}>
|
|
<Text style={styles.title}>记录方式</Text>
|
|
</View>
|
|
|
|
<View style={styles.menuGrid}>
|
|
{menuItems.map((item) => (
|
|
<TouchableOpacity
|
|
key={item.id}
|
|
style={styles.menuItem}
|
|
onPress={item.onPress}
|
|
activeOpacity={0.7}
|
|
>
|
|
<View style={[styles.iconContainer, { backgroundColor: item.backgroundColor }]}>
|
|
<Text style={styles.iconText}>{item.icon}</Text>
|
|
</View>
|
|
<Text style={styles.menuText}>{item.title}</Text>
|
|
</TouchableOpacity>
|
|
))}
|
|
</View>
|
|
</BlurView>
|
|
|
|
<TouchableOpacity
|
|
style={styles.closeButton}
|
|
onPress={onClose}
|
|
activeOpacity={0.7}
|
|
>
|
|
<View style={styles.closeButtonInner}>
|
|
<Ionicons name="close" size={24} color="#666" />
|
|
</View>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</BlurView>
|
|
</Modal>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
overlay: {
|
|
flex: 1,
|
|
justifyContent: 'flex-end',
|
|
alignItems: 'center',
|
|
},
|
|
backdrop: {
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
},
|
|
container: {
|
|
alignItems: 'center',
|
|
marginBottom: 40,
|
|
},
|
|
blurContainer: {
|
|
borderRadius: 20,
|
|
overflow: 'hidden',
|
|
backgroundColor: 'rgba(255, 255, 255, 0.95)',
|
|
minWidth: 340,
|
|
paddingVertical: 20,
|
|
paddingHorizontal: 16,
|
|
minHeight: 100
|
|
},
|
|
header: {
|
|
paddingBottom: 20,
|
|
alignItems: 'center',
|
|
},
|
|
title: {
|
|
fontSize: 12,
|
|
fontWeight: '600',
|
|
color: '#636161ff',
|
|
},
|
|
menuGrid: {
|
|
flexDirection: 'row',
|
|
justifyContent: 'space-around',
|
|
gap: 32,
|
|
},
|
|
menuItem: {
|
|
alignItems: 'center',
|
|
flex: 1,
|
|
},
|
|
iconContainer: {
|
|
width: 40,
|
|
height: 40,
|
|
borderRadius: 20,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
marginBottom: 8,
|
|
shadowColor: '#000',
|
|
shadowOffset: {
|
|
width: 0,
|
|
height: 2,
|
|
},
|
|
shadowOpacity: 0.15,
|
|
shadowRadius: 4,
|
|
elevation: 4,
|
|
},
|
|
iconText: {
|
|
fontSize: 16,
|
|
},
|
|
menuText: {
|
|
fontSize: 13,
|
|
fontWeight: '500',
|
|
color: '#333',
|
|
textAlign: 'center',
|
|
},
|
|
closeButton: {
|
|
marginTop: 20,
|
|
},
|
|
closeButtonInner: {
|
|
width: 44,
|
|
height: 44,
|
|
borderRadius: 22,
|
|
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
shadowColor: '#000',
|
|
shadowOffset: {
|
|
width: 0,
|
|
height: 2,
|
|
},
|
|
shadowOpacity: 0.1,
|
|
shadowRadius: 4,
|
|
elevation: 3,
|
|
},
|
|
}); |