- 新增自定义挑战创建页面,支持设置挑战类型、时间范围、目标值等 - 实现挑战邀请码系统,支持通过邀请码加入自定义挑战 - 完善挑战详情页面的多语言翻译支持 - 优化用户认证状态检查逻辑,使用token作为主要判断依据 - 添加阿里字体文件支持,提升UI显示效果 - 改进确认弹窗组件,支持Liquid Glass效果和自定义内容 - 优化应用启动流程,直接读取onboarding状态而非预加载用户数据
77 lines
2.5 KiB
TypeScript
77 lines
2.5 KiB
TypeScript
import { ThemedView } from '@/components/ThemedView';
|
|
import { ROUTES } from '@/constants/Routes';
|
|
import { usePushNotifications } from '@/hooks/usePushNotifications';
|
|
import { useThemeColor } from '@/hooks/useThemeColor';
|
|
import { STORAGE_KEYS } from '@/services/api';
|
|
import AsyncStorage from '@/utils/kvStore';
|
|
import { router } from 'expo-router';
|
|
import React, { useEffect, useState } from 'react';
|
|
import { ActivityIndicator, View } from 'react-native';
|
|
|
|
export default function SplashScreen() {
|
|
const backgroundColor = useThemeColor({}, 'background');
|
|
const primaryColor = useThemeColor({}, 'primary');
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const { initializePushNotifications } = usePushNotifications();
|
|
|
|
useEffect(() => {
|
|
checkOnboardingStatus();
|
|
}, []);
|
|
|
|
const checkOnboardingStatus = async () => {
|
|
try {
|
|
// 直接读取 onboarding 状态
|
|
console.log('检查 onboarding 状态...');
|
|
const onboardingCompletedStr = await AsyncStorage.getItem(STORAGE_KEYS.onboardingCompleted);
|
|
const onboardingCompleted = onboardingCompletedStr === 'true';
|
|
console.log('Onboarding 状态:', onboardingCompleted);
|
|
|
|
// 初始化推送通知(不阻塞应用启动,且不会请求权限)
|
|
console.log('开始初始化推送通知基础服务...');
|
|
initializePushNotifications().catch((error) => {
|
|
console.warn('推送通知初始化失败,但不影响应用正常使用:', error);
|
|
});
|
|
|
|
// 根据状态决定跳转
|
|
if (onboardingCompleted) {
|
|
console.log('用户已完成引导,跳转到统计页面');
|
|
router.replace(ROUTES.TAB_STATISTICS);
|
|
} else {
|
|
console.log('用户未完成引导,跳转到引导页面');
|
|
router.replace(ROUTES.ONBOARDING);
|
|
}
|
|
} 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>
|
|
);
|
|
}
|