Refactor components and enhance background task management
- Updated font sizes and weights in BasalMetabolismCard, MoodCard, HealthDataCard, and NutritionRadarCard for improved readability. - Removed loading state from MoodCard to simplify the component. - Adjusted styles in WeightHistoryCard for better layout and spacing. - Integrated expo-background-fetch for improved background task handling. - Updated Info.plist to include background fetch capability. - Enhanced background task registration and execution logic in backgroundTaskManager. - Added debug function to manually trigger background task execution for testing purposes.
This commit is contained in:
@@ -149,7 +149,7 @@ export default function ExploreScreen() {
|
||||
});
|
||||
}, [userProfile]);
|
||||
|
||||
const { registerTask } = useBackgroundTasks();
|
||||
const { registerTask, isInitialized } = useBackgroundTasks();
|
||||
// 心情相关状态
|
||||
const dispatch = useAppDispatch();
|
||||
const [isMoodLoading, setIsMoodLoading] = useState(false);
|
||||
@@ -416,27 +416,34 @@ export default function ExploreScreen() {
|
||||
}, [loadAllData, currentSelectedDate]);
|
||||
|
||||
useEffect(() => {
|
||||
// 注册后台任务 - 只处理健康数据和压力检查
|
||||
registerTask({
|
||||
id: 'health-data-task',
|
||||
name: 'health-data-task',
|
||||
handler: async () => {
|
||||
try {
|
||||
console.log('后台任务:更新健康数据和检查压力水平...');
|
||||
// 后台任务只更新健康数据,强制刷新以获取最新数据
|
||||
await loadHealthData(undefined, true);
|
||||
// 只有在后台任务管理器初始化完成后才注册任务
|
||||
if (isInitialized) {
|
||||
console.log('后台任务管理器已初始化,开始注册健康数据任务...');
|
||||
registerTask({
|
||||
id: 'health-data-task',
|
||||
name: 'health-data-task',
|
||||
handler: async () => {
|
||||
try {
|
||||
console.log('后台任务:更新健康数据和检查压力水平...');
|
||||
// 后台任务只更新健康数据,强制刷新以获取最新数据
|
||||
await loadHealthData(undefined, true);
|
||||
|
||||
// 执行压力检查
|
||||
await checkStressLevelAndNotify();
|
||||
// 执行压力检查
|
||||
await checkStressLevelAndNotify();
|
||||
|
||||
// 执行喝水目标检查
|
||||
await checkWaterGoalAndNotify();
|
||||
} catch (error) {
|
||||
console.error('健康数据任务执行失败:', error);
|
||||
}
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
// 执行喝水目标检查
|
||||
await checkWaterGoalAndNotify();
|
||||
} catch (error) {
|
||||
console.error('健康数据任务执行失败:', error);
|
||||
}
|
||||
},
|
||||
}).then(() => {
|
||||
console.log('健康数据任务注册成功');
|
||||
}).catch((error) => {
|
||||
console.error('健康数据任务注册失败:', error);
|
||||
});
|
||||
}
|
||||
}, [isInitialized]);
|
||||
|
||||
// 检查压力水平并发送通知
|
||||
const checkStressLevelAndNotify = React.useCallback(async () => {
|
||||
@@ -599,16 +606,18 @@ export default function ExploreScreen() {
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<WeightHistoryCard />
|
||||
|
||||
|
||||
{/* 日期选择器 */}
|
||||
<DateSelector
|
||||
selectedIndex={selectedIndex}
|
||||
onDateSelect={onSelectDate}
|
||||
showMonthTitle={true}
|
||||
showMonthTitle={false}
|
||||
disableFutureDates={true}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
{/* 营养摄入雷达图卡片 */}
|
||||
<NutritionRadarCard
|
||||
nutritionSummary={nutritionSummary}
|
||||
@@ -624,6 +633,8 @@ export default function ExploreScreen() {
|
||||
}}
|
||||
/>
|
||||
|
||||
<WeightHistoryCard />
|
||||
|
||||
{/* 真正瀑布流布局 */}
|
||||
<View style={styles.masonryContainer}>
|
||||
{/* 左列 */}
|
||||
@@ -768,7 +779,7 @@ const styles = StyleSheet.create({
|
||||
paddingHorizontal: 20,
|
||||
},
|
||||
headerContainer: {
|
||||
marginBottom: 20,
|
||||
marginBottom: 10,
|
||||
},
|
||||
headerContent: {
|
||||
flexDirection: 'row',
|
||||
@@ -1002,8 +1013,8 @@ const styles = StyleSheet.create({
|
||||
masonryContainer: {
|
||||
marginBottom: 16,
|
||||
flexDirection: 'row',
|
||||
gap: 12,
|
||||
marginTop: 16,
|
||||
gap: 16,
|
||||
marginTop: 6,
|
||||
},
|
||||
masonryColumn: {
|
||||
flex: 1,
|
||||
@@ -1023,6 +1034,7 @@ const styles = StyleSheet.create({
|
||||
elevation: 6,
|
||||
minHeight: 100,
|
||||
justifyContent: 'center',
|
||||
marginTop: 6
|
||||
},
|
||||
basalMetabolismCardOverride: {
|
||||
margin: -16, // 抵消 masonryCard 的 padding
|
||||
|
||||
Reference in New Issue
Block a user