/** * 根导航器 * 处理整个应用的顶级导航,包括认证状态切换 */ import React, { useEffect, useState } from 'react'; import { View, ActivityIndicator, StyleSheet } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import type { RootStackParamList } from './types'; import { colors } from '../theme'; import { navigationService } from '../infrastructure/navigation/navigationService'; import { AuthNavigator } from './AuthNavigator'; import { SimpleMobileTabNavigator } from './SimpleMobileTabNavigator'; import { DesktopNavigator } from './DesktopNavigator'; import { useResponsive } from '../hooks'; import { useTotalUnreadCount } from '../stores'; // 导入全局屏幕组件 import { PostDetailScreen } from '../screens/home'; import { UserScreen } from '../screens/profile'; import FollowListScreen from '../screens/profile/FollowListScreen'; import { CreatePostScreen } from '../screens/create'; import { ChatScreen, CreateGroupScreen, JoinGroupScreen, GroupInfoScreen, GroupMembersScreen, GroupRequestDetailScreen, GroupInviteDetailScreen, PrivateChatInfoScreen, } from '../screens/message'; const RootStack = createNativeStackNavigator(); interface RootNavigatorProps { isAuthenticated: boolean; isInitializing: boolean; } // 未认证时可访问的屏幕 const PublicScreens = () => ( <> ); // 认证后可访问的屏幕 const AuthenticatedScreens = () => ( <> ); export function RootNavigator({ isAuthenticated, isInitializing }: RootNavigatorProps) { const { isMobile } = useResponsive(); const unreadCount = useTotalUnreadCount(); // 设置导航引用 const setNavigationRef = (ref: any) => { navigationService.setNavigationRef(ref); }; // 加载中显示 if (isInitializing) { return ( ); } return ( {isAuthenticated ? ( <> {() => isMobile ? ( ) : ( ) } ) : ( <> )} ); } const styles = StyleSheet.create({ loadingContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: colors.background.default, }, });