- 在启动屏预加载用户 token 与资料,避免首页白屏 - 新增 rehydrateUserSync 同步注入 Redux,减少异步等待 - 登录页兼容 ERR_REQUEST_CANCELED 取消场景 - 各页面统一依赖 isLoggedIn 判断,移除冗余控制台日志 - 步数卡片与详情页改为实时拉取健康数据,不再缓存至 Redux - 后台任务注册移至顶层,防止重复定义 - 体重记录、HeaderBar 等 UI 细节样式微调
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { ThemedView } from '@/components/ThemedView';
|
|
import { ROUTES } from '@/constants/Routes';
|
|
import { useThemeColor } from '@/hooks/useThemeColor';
|
|
import { preloadUserData } from '@/store/userSlice';
|
|
import { router } from 'expo-router';
|
|
import React, { useEffect, useState } from 'react';
|
|
import { ActivityIndicator, View } from 'react-native';
|
|
|
|
const ONBOARDING_COMPLETED_KEY = '@onboarding_completed';
|
|
|
|
export default function SplashScreen() {
|
|
const backgroundColor = useThemeColor({}, 'background');
|
|
const primaryColor = useThemeColor({}, 'primary');
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
checkOnboardingStatus();
|
|
}, []);
|
|
|
|
const checkOnboardingStatus = async () => {
|
|
try {
|
|
// 先预加载用户数据,这样进入应用时就有正确的 token 状态
|
|
console.log('开始预加载用户数据...');
|
|
await preloadUserData();
|
|
console.log('用户数据预加载完成');
|
|
|
|
// const onboardingCompleted = await AsyncStorage.getItem(ONBOARDING_COMPLETED_KEY);
|
|
|
|
// if (onboardingCompleted === 'true') {
|
|
// router.replace('/(tabs)');
|
|
// } else {
|
|
// router.replace('/onboarding');
|
|
// }
|
|
// setIsLoading(false);
|
|
router.replace(ROUTES.TAB_STATISTICS);
|
|
} catch (error) {
|
|
console.error('检查引导状态或预加载用户数据失败:', error);
|
|
// 如果出现错误,仍然进入应用,但可能会有状态更新
|
|
router.replace(ROUTES.TAB_STATISTICS);
|
|
}
|
|
setIsLoading(false);
|
|
};
|
|
|
|
if (!isLoading) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<ThemedView style={{
|
|
flex: 1,
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
backgroundColor
|
|
}}>
|
|
<View style={{
|
|
width: 80,
|
|
height: 80,
|
|
borderRadius: 40,
|
|
// backgroundColor: primaryColor,
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
marginBottom: 20,
|
|
}}>
|
|
|
|
</View>
|
|
<ActivityIndicator size="large" color={primaryColor} />
|
|
</ThemedView>
|
|
);
|
|
}
|