import { router } from "expo-router"; import { ActivityIndicator, FlatList, Image, Text, TouchableOpacity, View, } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { GoogleTextInput } from "@/components/google-text-input"; import { LocationNotice } from "@/components/location-notice"; import { Map } from "@/components/map"; import { NearbySuggestions } from "@/components/nearby-suggestions"; import { RideCard } from "@/components/ride-card"; import { ServiceSelector } from "@/components/service-selector"; import { icons, images } from "@/constants"; import { useT } from "@/lib/i18n"; import { useSession } from "@/lib/session"; import { useTheme } from "@/lib/theme"; import { useUserLocation } from "@/lib/use-user-location"; import { useLocationStore } from "@/store"; import { useFetch } from "@/lib/fetch"; import type { Ride } from "@/types/type"; const Home = () => { const setDestinationLocation = useLocationStore( (state) => state.setDestinationLocation, ); const { signOut, user } = useSession(); const { isDark } = useTheme(); const t = useT(); const { data: recentRides, loading } = useFetch("/(api)/ride/list"); const { status: locationStatus, retry: retryLocation } = useUserLocation(); const handleSignOut = () => { signOut(); router.replace("/(auth)/sign-in"); }; const handleDestinationPress = (location: { latitude: number; longitude: number; address: string; }) => { setDestinationLocation(location); router.push("/(root)/find-ride"); }; return ( } className="px-5" keyboardShouldPersistTaps="handled" contentContainerStyle={{ paddingBottom: 100, }} ListEmptyComponent={ {!loading ? ( <> {t("home.noRecentAlt")} {t("home.noRecent")} ) : ( )} } // Passed as an *element*, not as `() => (...)`. VirtualizedList // renders a function prop as ``, so a fresh arrow // function each render is a fresh element type: React unmounts the // whole header — MapView included — and mounts a new one. Recreating // the Android map surface on every re-render leaves it grey with the // Google logo and tiles that never finish loading. ListHeaderComponent={ <> {t("home.welcome", { name: user?.name || user?.email || "" })} {t("home.logoutAlt")} {t("home.currentLocation")} {locationStatus === "pending" || locationStatus === "granted" ? ( <> {/* The map draws straight away on the Beirut fallback so the slot never sits empty while the fix is still coming. */} {locationStatus === "pending" ? ( {t("home.findingLocation")} ) : null} ) : ( )} {t("home.whatNeed")} {t("home.recentRides")} } /> ); }; export default Home;