- 添加 Redux 状态管理,支持用户登录和个人信息的持久化 - 新增目标管理页面,允许用户设置每日卡路里和步数目标 - 更新首页,移除旧的活动展示,改为固定的热点功能卡片 - 修改布局以适应新功能的展示和交互 - 更新依赖,添加 @reduxjs/toolkit 和 react-redux 库以支持状态管理 - 新增 API 服务模块,处理与后端的交互
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
|
|
import { useFonts } from 'expo-font';
|
|
import { Stack } from 'expo-router';
|
|
import { StatusBar } from 'expo-status-bar';
|
|
import 'react-native-reanimated';
|
|
|
|
import { useAppDispatch } from '@/hooks/redux';
|
|
import { useColorScheme } from '@/hooks/useColorScheme';
|
|
import { store } from '@/store';
|
|
import { rehydrateUser } from '@/store/userSlice';
|
|
import React from 'react';
|
|
import { Provider } from 'react-redux';
|
|
|
|
function Bootstrapper({ children }: { children: React.ReactNode }) {
|
|
const dispatch = useAppDispatch();
|
|
React.useEffect(() => {
|
|
dispatch(rehydrateUser());
|
|
}, [dispatch]);
|
|
return <>{children}</>;
|
|
}
|
|
|
|
export default function RootLayout() {
|
|
const colorScheme = useColorScheme();
|
|
const [loaded] = useFonts({
|
|
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
|
});
|
|
|
|
if (!loaded) {
|
|
// Async font loading only occurs in development.
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Provider store={store}>
|
|
<Bootstrapper>
|
|
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
|
<Stack screenOptions={{ headerShown: false }}>
|
|
<Stack.Screen name="onboarding" />
|
|
<Stack.Screen name="(tabs)" />
|
|
<Stack.Screen name="profile/edit" />
|
|
<Stack.Screen name="profile/goals" options={{ headerShown: false }} />
|
|
<Stack.Screen name="ai-posture-assessment" />
|
|
<Stack.Screen name="auth/login" options={{ headerShown: false }} />
|
|
<Stack.Screen name="legal/user-agreement" options={{ headerShown: true, title: '用户协议' }} />
|
|
<Stack.Screen name="legal/privacy-policy" options={{ headerShown: true, title: '隐私政策' }} />
|
|
<Stack.Screen name="+not-found" />
|
|
</Stack>
|
|
<StatusBar style="auto" />
|
|
</ThemeProvider>
|
|
</Bootstrapper>
|
|
</Provider>
|
|
);
|
|
}
|