import React, { useEffect, useState } from "react"; import { StatusBar } from "expo-status-bar"; import { ActivityIndicator, View } from "react-native"; import { NavigationContainer } from "@react-navigation/native"; import { createNativeStackNavigator } from "@react-navigation/native-stack"; import * as Updates from "expo-updates"; import { AuthProvider, useAuth } from "./src/auth/AuthContext"; import { CartProvider } from "./src/context/CartContext"; import { NotificationProvider } from "./src/context/NotificationContext"; import { ThemeProvider, useTheme } from "./src/context/ThemeContext"; import { initServerBaseUrl } from "./src/api/client"; import HomeScreen from "./src/screens/HomeScreen"; import ServerConfigScreen from "./src/screens/auth/ServerConfigScreen"; import ClientLoginScreen from "./src/screens/auth/ClientLoginScreen"; import ClientTwoFAScreen from "./src/screens/auth/ClientTwoFAScreen"; import ChangePasswordScreen from "./src/screens/auth/ChangePasswordScreen"; import ClientNavigator from "./src/navigation/ClientNavigator"; import type { RootStackParamList, ChangePasswordStackParamList } from "./src/navigation/types"; const Stack = createNativeStackNavigator(); const CPStack = createNativeStackNavigator(); function AuthStack() { const { colors } = useTheme(); return ( ); } function ForceChangePasswordStack() { const { colors } = useTheme(); return ( null }} /> ); } function RootNavigator() { const { isAuthenticated, isLoading, role, mustChangePassword } = useAuth(); const { colors, isDark } = useTheme(); if (isLoading) { return ( ); } if (isAuthenticated && role === "client" && mustChangePassword) { return ; } if (isAuthenticated && role === "client") { return ( ); } return ; } function AppContent() { const { isDark } = useTheme(); useEffect(() => { if (__DEV__) return; const checkForUpdate = async () => { try { const update = await Updates.checkForUpdateAsync(); if (update.isAvailable) { await Updates.fetchUpdateAsync(); await Updates.reloadAsync(); } } catch { // Silently ignore update errors } }; checkForUpdate(); }, []); return ( ); } export default function App() { return ( ); } // Restores a previously saved backend server URL before any screen // (including the auth restore flow) can issue an API call. function ServerGate({ children }: { children: React.ReactNode }) { const [ready, setReady] = useState(false); const { colors } = useTheme(); useEffect(() => { initServerBaseUrl().finally(() => setReady(true)); }, []); if (!ready) { return ( ); } return <>{children}; }