import React, { useMemo, useEffect } from "react"; import { StatusBar } from "expo-status-bar"; import { ActivityIndicator, View, StyleSheet } from "react-native"; import * as Updates from "expo-updates"; import AsyncStorage from "@react-native-async-storage/async-storage"; import { NavigationContainer } from "@react-navigation/native"; import { createNativeStackNavigator } from "@react-navigation/native-stack"; import { AuthProvider, useAuth } from "./src/auth/AuthContext"; import { ThemeProvider, useTheme } from "./src/context/ThemeContext"; import type { Colors } from "./src/theme"; import { spacing } from "./src/theme"; import RoleSelectScreen from "./src/screens/auth/RoleSelectScreen"; import AdminLoginScreen from "./src/screens/auth/AdminLoginScreen"; import CabineLoginScreen from "./src/screens/auth/CabineLoginScreen"; import DeliveryLoginScreen from "./src/screens/auth/DeliveryLoginScreen"; import AdminNavigator from "./src/navigation/AdminNavigator"; import CabineNavigator from "./src/navigation/CabineNavigator"; import DeliveryNavigator from "./src/navigation/DeliveryNavigator"; import type { AuthStackParamList } from "./src/navigation/types"; const Stack = createNativeStackNavigator(); const OTA_LAST_RELOAD_KEY = "ota_last_reload_update_id"; function AuthStack() { const { colors } = useTheme(); return ( ); } function RootNavigator() { const { isAuthenticated, isLoading, role } = useAuth(); const { colors } = useTheme(); if (isLoading) { return ( ); } if (isAuthenticated) { switch (role) { case "admin": return ; case "cabine": return ; case "livreur": return ; } } return ; } export default function App() { useEffect(() => { if (__DEV__) return; const checkForUpdate = async () => { try { const update = await Updates.checkForUpdateAsync(); const id = update.isAvailable ? update.manifest?.id : undefined; if (!id || id === Updates.updateId) return; // Déjà tentée : si elle ne tourne pas, on ne relance pas (évite la boucle) if ((await AsyncStorage.getItem(OTA_LAST_RELOAD_KEY)) === id) return; await Updates.fetchUpdateAsync(); await AsyncStorage.setItem(OTA_LAST_RELOAD_KEY, id); await Updates.reloadAsync(); } catch (e) { console.error("[OTA] Échec de la vérification/application de la mise à jour:", e); } }; checkForUpdate(); }, []); return ( ); } function DynamicStatusBar() { const { isDark } = useTheme(); return ; }