MCPcopy Create free account
hub / github.com/Galaxies-dev/airbnb-clone-react-native / ExploreHeader

Function ExploreHeader

components/ExploreHeader.tsx:44–108  ·  view source on GitHub ↗
({ onCategoryChanged }: Props)

Source from the content-addressed store, hash-verified

42}
43
44const ExploreHeader = ({ onCategoryChanged }: Props) => {
45 const scrollRef = useRef<ScrollView>(null);
46 const itemsRef = useRef<Array<TouchableOpacity | null>>([]);
47 const [activeIndex, setActiveIndex] = useState(0);
48
49 const selectCategory = (index: number) => {
50 const selected = itemsRef.current[index];
51 setActiveIndex(index);
52 selected?.measure((x) => {
53 scrollRef.current?.scrollTo({ x: x - 16, y: 0, animated: true });
54 });
55 Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
56 onCategoryChanged(categories[index].name);
57 };
58
59 return (
60 <SafeAreaView style={{ flex: 1, backgroundColor: '#fff' }}>
61 <View style={styles.container}>
62 <View style={styles.actionRow}>
63 <Link href={'/(modals)/booking'} asChild>
64 <TouchableOpacity>
65 <View style={styles.searchBtn}>
66 <Ionicons name="search" size={24} />
67 <View>
68 <Text style={{ fontFamily: 'mon-sb' }}>Where to?</Text>
69 <Text style={{ color: Colors.grey, fontFamily: 'mon' }}>Anywhere · Any week</Text>
70 </View>
71 </View>
72 </TouchableOpacity>
73 </Link>
74 <TouchableOpacity style={styles.filterBtn}>
75 <Ionicons name="options-outline" size={24} />
76 </TouchableOpacity>
77 </View>
78
79 <ScrollView
80 horizontal
81 ref={scrollRef}
82 showsHorizontalScrollIndicator={false}
83 contentContainerStyle={{
84 alignItems: 'center',
85 gap: 20,
86 paddingHorizontal: 16,
87 }}>
88 {categories.map((item, index) => (
89 <TouchableOpacity
90 ref={(el) => (itemsRef.current[index] = el)}
91 key={index}
92 style={activeIndex === index ? styles.categoriesBtnActive : styles.categoriesBtn}
93 onPress={() => selectCategory(index)}>
94 <MaterialIcons
95 name={item.icon as any}
96 size={24}
97 color={activeIndex === index ? '#000' : Colors.grey}
98 />
99 <Text style={activeIndex === index ? styles.categoryTextActive : styles.categoryText}>
100 {item.name}
101 </Text>

Callers

nothing calls this directly

Calls 1

selectCategoryFunction · 0.85

Tested by

no test coverage detected