freshyo/apps/user-ui/src/components/LocationBar.tsx
2026-10-13 13:51:16 +05:30

45 lines
1.8 KiB
TypeScript

import React, { useState } from 'react'
import { View } from 'react-native'
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
import { tw, theme, MyText, MyTouchableOpacity } from 'common-ui'
import { useRegion } from '@/src/hooks/useRegion'
import AddressSwitcherSheet from '@/src/components/location/AddressSwitcherSheet'
/**
* Location bar shown at the top of every top-level tab screen.
* Rendered INSIDE the scroll content (first item / ListHeaderComponent) so it
* scrolls out with the page instead of sticking. Tapping opens the address
* switcher: pick a saved address (region follows it) or add a new one.
*/
const LocationBar: React.FC = () => {
const [sheetOpen, setSheetOpen] = useState(false)
const { region } = useRegion()
return (
<View style={tw`px-4 pt-3 pb-1`}>
<MyTouchableOpacity
testID="location-bar"
activeOpacity={0.85}
onPress={() => setSheetOpen(true)}
style={tw`flex-row items-center bg-white border border-gray-100 rounded-2xl px-4 py-3 shadow-sm`}
>
<View style={tw`w-9 h-9 rounded-full bg-blue-50 items-center justify-center mr-3`}>
<MaterialIcons name="location-on" size={20} color={theme.colors.brand500} />
</View>
<View style={tw`flex-1`}>
<MyText style={tw`text-gray-400 text-[11px] font-semibold uppercase tracking-wider`}>
Deliver to
</MyText>
<MyText style={tw`text-gray-900 text-base font-bold`} numberOfLines={1}>
{region?.name ?? 'Choose your address'}
</MyText>
</View>
<MaterialIcons name="keyboard-arrow-down" size={24} color="#9CA3AF" />
</MyTouchableOpacity>
<AddressSwitcherSheet open={sheetOpen} onClose={() => setSheetOpen(false)} />
</View>
)
}
export default LocationBar