feat: 添加后台任务测试通知功能,优化滑动删除交互体验
This commit is contained in:
@@ -424,6 +424,19 @@ export default function ExploreScreen() {
|
|||||||
handler: async () => {
|
handler: async () => {
|
||||||
try {
|
try {
|
||||||
console.log('后台任务:更新健康数据和检查压力水平...');
|
console.log('后台任务:更新健康数据和检查压力水平...');
|
||||||
|
|
||||||
|
// 发送测试通知,验证后台任务是否执行
|
||||||
|
await notificationService.sendImmediateNotification({
|
||||||
|
title: '后台任务测试 🔔',
|
||||||
|
body: `任务执行时间: ${new Date().toLocaleTimeString('zh-CN')}`,
|
||||||
|
data: {
|
||||||
|
type: 'background_task_test',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
},
|
||||||
|
sound: true,
|
||||||
|
priority: 'high'
|
||||||
|
});
|
||||||
|
|
||||||
// 后台任务只更新健康数据,强制刷新以获取最新数据
|
// 后台任务只更新健康数据,强制刷新以获取最新数据
|
||||||
await loadHealthData(undefined, true);
|
await loadHealthData(undefined, true);
|
||||||
|
|
||||||
|
|||||||
@@ -138,20 +138,6 @@ export default function LoginScreen() {
|
|||||||
}
|
}
|
||||||
}, [appleAvailable, router, searchParams?.redirectParams, searchParams?.redirectTo]);
|
}, [appleAvailable, router, searchParams?.redirectParams, searchParams?.redirectTo]);
|
||||||
|
|
||||||
const onGuestLogin = useCallback(() => {
|
|
||||||
// 游客继续:若有 redirect 则前往,无则返回
|
|
||||||
const to = searchParams?.redirectTo as string | undefined;
|
|
||||||
const paramsJson = searchParams?.redirectParams as string | undefined;
|
|
||||||
let parsedParams: Record<string, any> | undefined;
|
|
||||||
if (paramsJson) {
|
|
||||||
try { parsedParams = JSON.parse(paramsJson); } catch { }
|
|
||||||
}
|
|
||||||
if (to) {
|
|
||||||
router.replace({ pathname: to, params: parsedParams } as any);
|
|
||||||
} else {
|
|
||||||
router.back();
|
|
||||||
}
|
|
||||||
}, [router, searchParams?.redirectParams, searchParams?.redirectTo]);
|
|
||||||
|
|
||||||
// 登录按钮不再因未勾选协议而禁用,仅在加载中禁用
|
// 登录按钮不再因未勾选协议而禁用,仅在加载中禁用
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Ionicons } from '@expo/vector-icons';
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import React, { useMemo, useRef, useState } from 'react';
|
import React, { useMemo, useRef, useState } from 'react';
|
||||||
import { Alert, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
import { Alert, Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
||||||
import { Swipeable } from 'react-native-gesture-handler';
|
import { RectButton, Swipeable } from 'react-native-gesture-handler';
|
||||||
|
|
||||||
export type NutritionRecordCardProps = {
|
export type NutritionRecordCardProps = {
|
||||||
record: DietRecord;
|
record: DietRecord;
|
||||||
@@ -53,6 +53,9 @@ export function NutritionRecordCard({
|
|||||||
// 左滑删除相关
|
// 左滑删除相关
|
||||||
const swipeableRef = useRef<Swipeable>(null);
|
const swipeableRef = useRef<Swipeable>(null);
|
||||||
|
|
||||||
|
// 添加滑动状态管理,防止滑动时触发点击事件
|
||||||
|
const [isSwiping, setIsSwiping] = useState(false);
|
||||||
|
|
||||||
// 营养数据统计
|
// 营养数据统计
|
||||||
const nutritionStats = useMemo(() => {
|
const nutritionStats = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
@@ -80,6 +83,26 @@ export function NutritionRecordCard({
|
|||||||
const mealTypeColor = MEAL_TYPE_COLORS[record.mealType];
|
const mealTypeColor = MEAL_TYPE_COLORS[record.mealType];
|
||||||
const mealTypeLabel = MEAL_TYPE_LABELS[record.mealType];
|
const mealTypeLabel = MEAL_TYPE_LABELS[record.mealType];
|
||||||
|
|
||||||
|
// 处理点击事件,只有在非滑动状态下才触发
|
||||||
|
const handlePress = () => {
|
||||||
|
if (!isSwiping && onPress) {
|
||||||
|
onPress();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 处理滑动开始
|
||||||
|
const handleSwipeableWillOpen = () => {
|
||||||
|
setIsSwiping(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 处理滑动结束
|
||||||
|
const handleSwipeableClose = () => {
|
||||||
|
// 延迟重置滑动状态,防止滑动结束时立即触发点击
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsSwiping(false);
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
// 处理删除操作
|
// 处理删除操作
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
@@ -123,14 +146,16 @@ export function NutritionRecordCard({
|
|||||||
renderRightActions={renderRightActions}
|
renderRightActions={renderRightActions}
|
||||||
rightThreshold={40}
|
rightThreshold={40}
|
||||||
overshootRight={false}
|
overshootRight={false}
|
||||||
|
onSwipeableWillOpen={handleSwipeableWillOpen}
|
||||||
|
onSwipeableClose={handleSwipeableClose}
|
||||||
>
|
>
|
||||||
<TouchableOpacity
|
<RectButton
|
||||||
style={[
|
style={[
|
||||||
styles.card,
|
styles.card,
|
||||||
{ backgroundColor: surfaceColor }
|
|
||||||
]}
|
]}
|
||||||
onPress={onPress}
|
onPress={handlePress}
|
||||||
activeOpacity={0.7}
|
// activeOpacity={0.7}
|
||||||
>
|
>
|
||||||
{/* 主要内容区域 - 水平布局 */}
|
{/* 主要内容区域 - 水平布局 */}
|
||||||
<View style={styles.mainContent}>
|
<View style={styles.mainContent}>
|
||||||
@@ -186,7 +211,7 @@ export function NutritionRecordCard({
|
|||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</RectButton>
|
||||||
</Swipeable>
|
</Swipeable>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user