2026-03-09 21:29:03 +08:00
|
|
|
|
/**
|
2026-03-18 12:11:49 +08:00
|
|
|
|
* 主导航组件(重构版)
|
|
|
|
|
|
*
|
|
|
|
|
|
* 此文件仅保留导航器组装逻辑,所有业务逻辑已解耦至:
|
|
|
|
|
|
* - RootNavigator: 处理根导航和认证状态
|
|
|
|
|
|
* - DesktopNavigator: 处理桌面端侧边栏导航
|
|
|
|
|
|
* - SimpleMobileTabNavigator: 处理移动端 Tab 导航
|
|
|
|
|
|
* - navigationService: 提供全局导航方法
|
|
|
|
|
|
*
|
|
|
|
|
|
* 原文件 1118 行已精简至约 200 行
|
2026-03-09 21:29:03 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
2026-03-18 12:11:49 +08:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
import { LinkingOptions } from '@react-navigation/native';
|
|
|
|
|
|
import { Platform } from 'react-native';
|
|
|
|
|
|
|
|
|
|
|
|
import type { RootStackParamList } from './types';
|
|
|
|
|
|
import { RootNavigator } from './RootNavigator';
|
|
|
|
|
|
|
|
|
|
|
|
// 导入认证 Store
|
|
|
|
|
|
import { useAuthStore } from '../stores';
|
|
|
|
|
|
|
|
|
|
|
|
// Deep linking 配置
|
|
|
|
|
|
const linking: LinkingOptions<RootStackParamList> = {
|
|
|
|
|
|
prefixes: [],
|
|
|
|
|
|
config: {
|
|
|
|
|
|
screens: {
|
|
|
|
|
|
Auth: {
|
|
|
|
|
|
screens: {
|
|
|
|
|
|
Login: 'login',
|
|
|
|
|
|
Register: 'register',
|
|
|
|
|
|
ForgotPassword: 'forgot-password',
|
2026-03-09 21:29:03 +08:00
|
|
|
|
},
|
2026-03-18 12:11:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
Main: {
|
|
|
|
|
|
screens: {
|
|
|
|
|
|
HomeTab: {
|
|
|
|
|
|
screens: {
|
|
|
|
|
|
Home: 'home',
|
|
|
|
|
|
Search: 'search',
|
2026-03-09 21:29:03 +08:00
|
|
|
|
},
|
2026-03-18 12:11:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
MessageTab: {
|
|
|
|
|
|
screens: {
|
|
|
|
|
|
MessageList: 'messages',
|
|
|
|
|
|
Notifications: 'notifications',
|
2026-03-09 21:29:03 +08:00
|
|
|
|
},
|
2026-03-18 12:11:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
ProfileTab: {
|
|
|
|
|
|
screens: {
|
|
|
|
|
|
Profile: 'me',
|
|
|
|
|
|
Settings: 'settings',
|
|
|
|
|
|
EditProfile: 'me/edit',
|
|
|
|
|
|
AccountSecurity: 'me/security',
|
|
|
|
|
|
NotificationSettings: 'me/notifications',
|
|
|
|
|
|
BlockedUsers: 'me/blocked',
|
2026-03-09 21:29:03 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2026-03-18 12:11:49 +08:00
|
|
|
|
PostDetail: 'posts/:postId',
|
|
|
|
|
|
UserProfile: 'users/:userId',
|
|
|
|
|
|
CreatePost: 'posts/create',
|
|
|
|
|
|
Chat: 'chat/:conversationId',
|
|
|
|
|
|
FollowList: 'users/:userId/:type',
|
2026-03-09 21:29:03 +08:00
|
|
|
|
},
|
2026-03-18 12:11:49 +08:00
|
|
|
|
},
|
|
|
|
|
|
};
|
2026-03-09 21:29:03 +08:00
|
|
|
|
|
2026-03-18 12:11:49 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 主导航组件
|
|
|
|
|
|
*
|
|
|
|
|
|
* 职责:
|
|
|
|
|
|
* 1. 初始化认证状态
|
|
|
|
|
|
* 2. 根据认证状态渲染 RootNavigator
|
|
|
|
|
|
* 3. 配置 Deep Linking
|
|
|
|
|
|
*/
|
|
|
|
|
|
export default function MainNavigator() {
|
|
|
|
|
|
const { isAuthenticated, fetchCurrentUser } = useAuthStore();
|
|
|
|
|
|
const [isInitializing, setIsInitializing] = useState(true);
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化认证状态
|
2026-03-09 21:29:03 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const initAuth = async () => {
|
|
|
|
|
|
await fetchCurrentUser();
|
2026-03-18 12:11:49 +08:00
|
|
|
|
setIsInitializing(false);
|
2026-03-09 21:29:03 +08:00
|
|
|
|
};
|
|
|
|
|
|
initAuth();
|
|
|
|
|
|
}, [fetchCurrentUser]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2026-03-18 12:11:49 +08:00
|
|
|
|
<RootNavigator
|
|
|
|
|
|
isAuthenticated={isAuthenticated}
|
|
|
|
|
|
isInitializing={isInitializing}
|
|
|
|
|
|
/>
|
2026-03-09 21:29:03 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-18 12:11:49 +08:00
|
|
|
|
// 导出 linking 配置供外部使用
|
|
|
|
|
|
export { linking };
|