feat: 修复健康数据

This commit is contained in:
2025-09-24 09:43:17 +08:00
parent e6dfd4d59a
commit 028ef56caf
8 changed files with 175 additions and 105 deletions

View File

@@ -1,12 +1,12 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
Animated,
InteractionManager,
StyleSheet,
Text,
TouchableOpacity,
View,
ViewStyle,
InteractionManager
ViewStyle
} from 'react-native';
import { fetchHourlyStepSamples, fetchStepCount, HourlyStepData } from '@/utils/health';
@@ -39,18 +39,12 @@ const StepsCard: React.FC<StepsCardProps> = ({
logger.info('获取步数数据...');
// 先获取步数立即更新UI
const steps = await fetchStepCount(date);
const [steps, hourly] = await Promise.all([
fetchStepCount(date),
fetchHourlyStepSamples(date)
]);
setStepCount(steps);
// 使用 InteractionManager 在空闲时获取更复杂的小时数据
InteractionManager.runAfterInteractions(async () => {
try {
const hourly = await fetchHourlyStepSamples(date);
setHourSteps(hourly);
} catch (error) {
logger.error('获取小时步数数据失败:', error);
}
});
setHourSteps(hourly);
} catch (error) {
logger.error('获取步数数据失败:', error);