wellnua-lite/app/_layout.tsx
Sergei 5e550f0f2b WellNuo Lite - готово для модерации Apple
- Добавлены страницы Privacy Policy и Terms of Service
- Обновлён chat и profile
- Конфигурация для App Store submission
2025-12-26 19:17:32 -08:00

65 lines
2.0 KiB
TypeScript

import { useEffect } from 'react';
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { Stack, router, useSegments } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import * as SplashScreen from 'expo-splash-screen';
import 'react-native-reanimated';
import { useColorScheme } from '@/hooks/use-color-scheme';
import { AuthProvider, useAuth } from '@/contexts/AuthContext';
import { BeneficiaryProvider } from '@/contexts/BeneficiaryContext';
import { LoadingSpinner } from '@/components/ui/LoadingSpinner';
// Prevent auto-hiding splash screen
SplashScreen.preventAutoHideAsync();
function RootLayoutNav() {
const colorScheme = useColorScheme();
const { isAuthenticated, isLoading } = useAuth();
const segments = useSegments();
useEffect(() => {
if (isLoading) return;
// Hide splash screen once we know auth state
SplashScreen.hideAsync();
const inAuthGroup = segments[0] === '(auth)';
if (!isAuthenticated && !inAuthGroup) {
// Redirect to login if not authenticated
router.replace('/(auth)/login');
} else if (isAuthenticated && inAuthGroup) {
// Redirect to main app if authenticated
router.replace('/(tabs)');
}
}, [isAuthenticated, isLoading, segments]);
if (isLoading) {
return <LoadingSpinner fullScreen message="Loading..." />;
}
return (
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen name="(auth)" />
<Stack.Screen name="(tabs)" />
<Stack.Screen name="modal" options={{ presentation: 'modal', title: 'Modal' }} />
<Stack.Screen name="terms" options={{ presentation: 'modal' }} />
<Stack.Screen name="privacy" options={{ presentation: 'modal' }} />
</Stack>
<StatusBar style="auto" />
</ThemeProvider>
);
}
export default function RootLayout() {
return (
<AuthProvider>
<BeneficiaryProvider>
<RootLayoutNav />
</BeneficiaryProvider>
</AuthProvider>
);
}