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 { useSession } from "@/lib/session"; 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 { 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 ? ( <> No recent rides found No recent rides found. ) : ( )} } // 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={ <> Welcome {user?.name || user?.email} 👋 Logout Your Current Location {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" ? ( Finding your location… ) : null} ) : ( )} What do you need? Recent Rides } /> ); }; export default Home;