CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { View, ActivityIndicator } from 'react-native';
import { colors } from '../theme/colors';
import { AuthScreen } from '../screens/AuthScreen';
import { MainTabNavigator } from './MainTabNavigator';
import { useAuth } from '../hooks/useAuth';
import { AuthContext } from './AuthContext';
// Re-export AuthContext so callers can do: import { AuthContext } from '../navigation/RootNavigator'
export { AuthContext };
export type { AuthContextValue } from './AuthContext';
// ─── Root param list ──────────────────────────────────────────────────────────
type RootStackParamList = {
Auth: undefined;
Main: undefined;
};
const Stack = createNativeStackNavigator<RootStackParamList>();
// ─── Navigator ────────────────────────────────────────────────────────────────
export function RootNavigator() {
const auth = useAuth();
if (auth.loading) {
return (
<View style={{ flex: 1, backgroundColor: colors.bg, alignItems: 'center', justifyContent: 'center' }}>
<ActivityIndicator size="large" color={colors.accent} />
</View>
);
}
return (
<AuthContext.Provider
value={{
user: auth.user,
token: auth.token,
login: auth.login,
logout: auth.logout,
}}
>
<NavigationContainer
theme={{
dark: true,
colors: {
primary: colors.accent,
background: colors.bg,
card: colors.bgSecondary,
text: colors.text,
border: colors.border,
notification: colors.accent,
},
}}
>
<Stack.Navigator screenOptions={{ headerShown: false }}>
{auth.isAuthenticated ? (
<Stack.Screen name="Main" component={MainTabNavigator} />
) : (
<Stack.Screen name="Auth" component={AuthScreen} />
)}
</Stack.Navigator>
</NavigationContainer>
</AuthContext.Provider>
);
}
|