Shop home

A photo-forward store home: live search, category chips that fill as the grid's tiles zoom out and glide into place, a paged promo carousel whose photo breaks the card edge and drifts as you swipe, and a sortable two-column grid. Hearts and quick-add buttons pop, and the bag badge bounces as its count rolls.

shopproduct gridsearchcategoriescarouselecommerceanimationreanimated
Paste into Claude Code Cursor Codex Lovable RapidNative
Live preview · follows the site themeOpen full screen

Details

File
components/patterns/product-grid.tsx
Lines
770
Stack
React Native, StyleSheet
Packages
expo-linear-gradient, lucide-react-native, react-native-reanimated, react-native-safe-area-context, react-native-svg, react-native-worklets
Platforms
iOS, Android, Web

Using gluestack-ui?

Optional. The screen is plain React Native; these components can stand in for its primitives.

components/patterns/product-grid.tsx
1import { useEffect, useMemo, useRef, useState, type ComponentRef, type ReactNode } from 'react';
2import { Image, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme, useWindowDimensions, type LayoutChangeEvent } from 'react-native';
3import Animated, {
4 cancelAnimation,
5 Easing,
6 FadeIn,
7 FadeInDown,
8 LinearTransition,
9 ZoomIn,
10 ZoomOut,
11 interpolate,
12 interpolateColor,
13 useAnimatedScrollHandler,
14 useAnimatedStyle,
15 useSharedValue,
16 withRepeat,
17 withSequence,
18 withSpring,
19 withTiming,
20 type SharedValue,
21} from 'react-native-reanimated';
22import { LinearGradient } from 'expo-linear-gradient';
23import { useSafeAreaInsets } from 'react-native-safe-area-context';
24import Svg, { Circle } from 'react-native-svg';
25import { ArrowRight, Check, ChevronDown, Heart, House, Plus, Search, SearchX, ShoppingBag, Star, UserRound, X } from 'lucide-react-native';
26
27// ─── Brand ──────────────────────────────────────────────────────────────────
28// The screen's accent and name. Every accent colour below derives from these, so changing them rebrands the screen.
29
30const ACCENT = '#E11D48';
31const ACCENT_DARK = '#FB4169'; // the accent on dark backgrounds
32const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
33
34/** `hex` with its hue turned by `deg` degrees and its HSL lightness and saturation moved by `light` / `sat` (-1 to 1). */
35function spin(hex: string, deg: number, light = 0, sat = 0) {
36 const n = parseInt(hex.slice(1), 16);
37 const r = ((n >> 16) & 255) / 255;
38 const g = ((n >> 8) & 255) / 255;
39 const b = (n & 255) / 255;
40 const max = Math.max(r, g, b);
41 const min = Math.min(r, g, b);
42 const d = max - min;
43 const s = Math.min(1, Math.max(0, (d === 0 ? 0 : d / (1 - Math.abs(max + min - 1))) + sat));
44 const l = Math.min(1, Math.max(0, (max + min) / 2 + light));
45 const h0 = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
46 const h = (((h0 * 60 + deg) % 360) + 360) % 360;
47 const a = s * Math.min(l, 1 - l);
48 const f = (m: number) => {
49 const k = (m + h / 30) % 12;
50 return Math.round(255 * (l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)))).toString(16).padStart(2, '0');
51 };
52 return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();
53}
54const APP_NAME = 'Hartley & Co.'; // the store's name
55
56// ─── Sample data ────────────────────────────────────────────────────────────
57
58const photo = (id: string, w = 600) => `https://images.unsplash.com/photo-${id}?w=${w}&q=80&fit=crop`;
59
60const SHOPPER = 'Maya';
61
62type Category = 'Shoes' | 'Audio' | 'Watches' | 'Travel' | 'Eyewear';
63type Filter = 'All' | Category;
64const FILTERS: Filter[] = ['All', 'Shoes', 'Audio', 'Watches', 'Travel', 'Eyewear'];
65
66type Product = {
67 id: string;
68 name: string;
69 category: Category;
70 finish: string;
71 price: number;
72 was?: number;
73 isNew?: boolean;
74 rating: number;
75 reviews: number;
76 image: string;
77 /** Width over height of the source photo, and where the product sits along its long side (0 to 1). */
78 ratio: number;
79 focus?: number;
80 tint: string;
81};
82
83// In "Featured" order.
84const PRODUCTS: Product[] = [
85 { id: 'derby', name: 'Weekend Derby', category: 'Shoes', finish: 'Sage suede', price: 159, was: 199, rating: 4.8, reviews: 212, image: photo('1560343090-f0409e92791a'), ratio: 0.8, tint: '#EAD8CE' },
86 { id: 'overear', name: 'Studio Over-Ear', category: 'Audio', finish: 'Matte black', price: 189, rating: 4.7, reviews: 238, image: photo('1505740420928-5e560c06d30e'), ratio: 1.5, focus: 0.8, tint: '#F6C415' },
87 { id: 'daypack', name: 'Canvas Day Pack', category: 'Travel', finish: 'Navy, 18 L', price: 89, isNew: true, rating: 4.6, reviews: 531, image: photo('1553062407-98eeb64c6a62'), ratio: 0.667, focus: 0.45, tint: '#C5CBD6' },
88 { id: 'meridian', name: 'Meridian Watch', category: 'Watches', finish: 'Graphite', price: 329, rating: 4.9, reviews: 96, image: photo('1546868871-7041f2a55e12'), ratio: 0.8, tint: '#ECECEC' },
89 { id: 'flask', name: 'Trail Flask', category: 'Travel', finish: 'Forest, 500 ml', price: 34, rating: 4.7, reviews: 164, image: photo('1602143407151-7111542de6e8'), ratio: 0.667, focus: 0.92, tint: '#DDE3DC' },
90 { id: 'riviera', name: 'Riviera Round', category: 'Eyewear', finish: 'Gold, green lens', price: 95, isNew: true, rating: 4.5, reviews: 88, image: photo('1511499767150-a48a237f0083'), ratio: 1, tint: '#EEEBE6' },
91 { id: 'square', name: 'Classic Square', category: 'Eyewear', finish: 'Polished black', price: 65, rating: 4.4, reviews: 309, image: photo('1572635196237-14b3f281503f'), ratio: 1, focus: 0.7, tint: '#E3E3E3' },
92 { id: 'runner', name: 'Aero Knit Runner', category: 'Shoes', finish: 'Black knit', price: 103, was: 129, rating: 4.8, reviews: 412, image: photo('1491553895911-0055eca6402d'), ratio: 1, tint: '#EFEFEF' },
93];
94
95type Promo = {
96 id: string;
97 eyebrow: string;
98 title: string;
99 cta: string;
100 goTo: Category;
101 colors: readonly [string, string];
102 ink: string;
103 pill: string;
104 pillInk: string;
105 image: string;
106 alt: string;
107 ratio: number;
108 focus: number;
109 zoom: number;
110};
111
112// The first promo is the store's own season, so it wears the accent; the audio and watch promos keep their own palettes.
113const PROMOS: Promo[] = [
114 { id: 'season', eyebrow: 'The autumn edit', title: 'New season,\n20% off', cta: 'Shop now', goTo: 'Shoes', colors: [spin(ACCENT, 2, 0.127, 0.145), spin(ACCENT, -2, -0.108, 0.078)], ink: ON_ACCENT, pill: '#FFFFFF', pillInk: spin(ACCENT, -3.5, -0.151, 0.025), image: photo('1491553895911-0055eca6402d', 400), alt: 'Black knit running shoe', ratio: 1, focus: 0.5, zoom: 1.35 },
115 { id: 'sound', eyebrow: 'Sound studio', title: 'Hear every\nlast detail', cta: 'Shop audio', goTo: 'Audio', colors: ['#FFCB45', '#FF9A1F'], ink: '#2A1803', pill: '#2A1803', pillInk: '#FFD877', image: photo('1583394838336-acd977736f90', 400), alt: 'Wired studio headphones', ratio: 0.66, focus: 0.55, zoom: 1 },
116 { id: 'time', eyebrow: 'Timepieces', title: 'Time, kept\nsimple', cta: 'Shop watches', goTo: 'Watches', colors: ['#659C8B', '#284A3F'], ink: '#FFFFFF', pill: '#FFFFFF', pillInk: '#234237', image: photo('1523275335684-37898b6baf30', 400), alt: 'Two white minimalist watches', ratio: 1.376, focus: 0.7, zoom: 1 },
117];
118
119const SORTS = [
120 { key: 'featured', label: 'Featured' },
121 { key: 'low', label: 'Price: low to high' },
122 { key: 'high', label: 'Price: high to low' },
123] as const;
124
125const TABS = [
126 { label: 'Home', icon: House },
127 { label: 'Search', icon: Search },
128 { label: 'Saved', icon: Heart },
129 { label: 'Bag', icon: ShoppingBag },
130 { label: 'Profile', icon: UserRound },
131];
132
133// ─── Palette ────────────────────────────────────────────────────────────────
134
135const INK = '#0A0A0A';
136const STAR = '#F59E0B';
137const ADDED = '#16A34A';
138const SPRING = { damping: 18, stiffness: 260, mass: 0.7 };
139const HEADER_H = 116;
140const TAB_H = 56;
141
142function usePalette() {
143 const dark = useColorScheme() === 'dark';
144 return {
145 dark,
146 bg: dark ? '#0A0A0A' : '#FAFAF9',
147 fg: dark ? '#FAFAFA' : INK,
148 inverse: dark ? INK : '#FAFAFA',
149 muted: dark ? '#A1A1AA' : '#71717A',
150 faint: dark ? '#5A5A60' : '#A8A29E',
151 chip: dark ? '#1A1A1D' : '#F0EFEC',
152 line: dark ? '#242428' : '#E7E5E4',
153 accent: dark ? ACCENT_DARK : ACCENT,
154 // A hairline keeps white studio shots from melting into the light background.
155 tileEdge: dark ? 'transparent' : 'rgba(0,0,0,0.07)',
156 };
157}
158type Palette = ReturnType<typeof usePalette>;
159
160// Scale up past the target, then settle: used by the heart, the quick-add button and the bag badge.
161const pop = (peak: number) =>
162 withSequence(withTiming(peak, { duration: 140, easing: Easing.out(Easing.back(2.4)) }), withTiming(1, { duration: 190, easing: Easing.out(Easing.cubic) }));
163
164// ─── Small pieces ───────────────────────────────────────────────────────────
165
166function Tap({ children, label, onPress, to = 0.92, role = 'button' }: { children: ReactNode; label: string; onPress?: () => void; to?: number; role?: 'button' | 'link' }) {
167 const scale = useSharedValue(1);
168 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
169 return (
170 <Pressable role={role} aria-label={label} onPress={onPress} hitSlop={6} onPressIn={() => (scale.value = withSpring(to, SPRING))} onPressOut={() => (scale.value = withSpring(1, SPRING))}>
171 <Animated.View style={style}>{children}</Animated.View>
172 </Pressable>
173 );
174}
175
176/**
177 * A photo that fades in over a tinted, pulsing placeholder. It covers its frame and slides
178 * along its long side to `focus`, so a wide studio shot keeps the product inside a tall tile.
179 */
180function Photo({ uri, alt, width, height, ratio, focus = 0.5, zoom = 1, tint }: { uri: string; alt: string; width: number; height: number; ratio: number; focus?: number; zoom?: number; tint: string }) {
181 const shown = useSharedValue(0);
182 const pulse = useSharedValue(0.15);
183 useEffect(() => {
184 pulse.value = withRepeat(withSequence(withTiming(0.5, { duration: 700 }), withTiming(0.15, { duration: 700 })), -1);
185 return () => cancelAnimation(pulse);
186 }, [pulse]);
187 const image = useAnimatedStyle(() => ({ opacity: shown.value, transform: [{ scale: zoom }] }));
188 const placeholder = useAnimatedStyle(() => ({ opacity: (1 - shown.value) * pulse.value }));
189 const wide = ratio > width / height;
190 const w = wide ? height * ratio : width;
191 const h = wide ? height : width / ratio;
192 return (
193 <View style={[styles.photo, { width, height, backgroundColor: tint }]}>
194 <Animated.View style={[StyleSheet.absoluteFill, styles.photoFlash, placeholder]} />
195 <Animated.View style={[styles.photoFrame, { left: wide ? -(w - width) * focus : 0, top: wide ? 0 : -(h - height) * focus, width: w, height: h }, image]}>
196 <Image
197 source={{ uri }}
198 alt={alt}
199 resizeMode="cover"
200 style={{ width: w, height: h }}
201 onLoad={() => {
202 cancelAnimation(pulse);
203 shown.value = withTiming(1, { duration: 320 });
204 }}
205 />
206 </Animated.View>
207 </View>
208 );
209}
210
211/** The bag count. It pops whenever the number changes, and the new digit rolls in. */
212function CountBadge({ count, ring, color }: { count: number; ring: string; color: string }) {
213 const scale = useSharedValue(1);
214 const last = useRef(count);
215 useEffect(() => {
216 if (last.current === count) return;
217 last.current = count;
218 scale.value = pop(1.45);
219 }, [count, scale]);
220 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
221 return (
222 <Animated.View
223 pointerEvents="none"
224 style={[styles.badge, { backgroundColor: color, borderColor: ring }, style]}
225 >
226 <Animated.Text key={count} entering={FadeInDown.duration(180)} style={[styles.badgeText, styles.tabular]}>
227 {count}
228 </Animated.Text>
229 </Animated.View>
230 );
231}
232
233// ─── Search field and category chips ────────────────────────────────────────
234
235function SearchField({ value, onChange, inputRef, pal }: { value: string; onChange: (v: string) => void; inputRef: React.RefObject<ComponentRef<typeof TextInput> | null>; pal: Palette }) {
236 const [focused, setFocused] = useState(false);
237 const ring = useSharedValue(0);
238 useEffect(() => {
239 ring.value = withTiming(focused ? 1 : 0, { duration: 180 });
240 }, [focused, ring]);
241 const box = useAnimatedStyle(() => ({ borderColor: interpolateColor(ring.value, [0, 1], [pal.chip, pal.fg]) }));
242 return (
243 <Animated.View style={[styles.search, { backgroundColor: pal.chip }, box]}>
244 <Search size={18} color={focused ? pal.fg : pal.muted} strokeWidth={2.2} />
245 <TextInput
246 ref={inputRef}
247 value={value}
248 onChangeText={onChange}
249 onFocus={() => setFocused(true)}
250 onBlur={() => setFocused(false)}
251 placeholder="Search shoes, watches, audio"
252 placeholderTextColor={pal.muted}
253 selectionColor={pal.accent}
254 aria-label="Search products"
255 autoCapitalize="none"
256 autoCorrect={false}
257 returnKeyType="search"
258 style={[styles.searchInput, { color: pal.fg }, Platform.OS === 'web' ? ({ outlineStyle: 'none' } as object) : null]}
259 />
260 {value.length > 0 && (
261 <Animated.View entering={ZoomIn.duration(160)} exiting={ZoomOut.duration(120)}>
262 <Pressable
263 role="button"
264 aria-label="Clear search"
265 hitSlop={8}
266 onPress={() => {
267 onChange('');
268 inputRef.current?.focus();
269 }}
270 style={[styles.searchClear, { backgroundColor: pal.faint }]}
271 >
272 <X size={14} color={pal.chip} strokeWidth={3} />
273 </Pressable>
274 </Animated.View>
275 )}
276 </Animated.View>
277 );
278}
279
280function Chip({ label, selected, onPress, onMeasure, pal }: { label: string; selected: boolean; onPress: () => void; onMeasure: (x: number) => void; pal: Palette }) {
281 const on = useSharedValue(selected ? 1 : 0);
282 useEffect(() => {
283 on.value = withTiming(selected ? 1 : 0, { duration: 220, easing: Easing.out(Easing.cubic) });
284 }, [selected, on]);
285 // The fill grows in from the centre while the label swaps to the inverse colour.
286 const fill = useAnimatedStyle(() => ({ opacity: on.value, transform: [{ scale: 0.8 + on.value * 0.2 }] }));
287 const text = useAnimatedStyle(() => ({ color: interpolateColor(on.value, [0, 1], [pal.fg, pal.inverse]) }));
288 return (
289 <Pressable role="tab" aria-selected={selected} aria-label={label} onPress={onPress} onLayout={(e: LayoutChangeEvent) => onMeasure(e.nativeEvent.layout.x)} style={[styles.chip, { backgroundColor: pal.chip }]}>
290 <Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, styles.chipFill, { backgroundColor: pal.fg }, fill]} />
291 <Animated.Text style={[styles.chipLabel, text]}>{label}</Animated.Text>
292 </Pressable>
293 );
294}
295
296// ─── Promo carousel: paged, the photo breaks the top edge and drifts as you swipe ───
297
298const BANNER_H = 150;
299const BREAKOUT = 24;
300const FRAME = 128;
301
302function Banner({ promo, index, x, width, onShop }: { promo: Promo; index: number; x: SharedValue<number>; width: number; onShop: () => void }) {
303 const drift = useAnimatedStyle(() => {
304 const t = Math.max(-1, Math.min(1, x.value / width - index));
305 return { transform: [{ translateX: interpolate(t, [-1, 0, 1], [24, 0, -24]) }, { rotate: `${interpolate(t, [-1, 0, 1], [12, 7, 2])}deg` }] };
306 });
307 return (
308 <View style={[styles.banner, { width }]}>
309 <View style={styles.bannerCard}>
310 <LinearGradient colors={promo.colors} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={[StyleSheet.absoluteFill, styles.bannerFill]}>
311 {/* Drawn rings behind the photo */}
312 <Svg width={260} height={260} style={styles.rings}>
313 <Circle cx={130} cy={130} r={128} stroke={promo.ink} strokeOpacity={0.14} strokeWidth={1.5} fill="none" />
314 <Circle cx={130} cy={130} r={96} stroke={promo.ink} strokeOpacity={0.18} strokeWidth={1.5} fill="none" />
315 <Circle cx={130} cy={130} r={64} fill={promo.ink} fillOpacity={0.1} />
316 </Svg>
317 </LinearGradient>
318
319 <View style={styles.bannerBody}>
320 <Text style={[styles.eyebrow, { color: promo.ink }]}>{promo.eyebrow}</Text>
321 <Text style={[styles.bannerTitle, { color: promo.ink }]}>{promo.title}</Text>
322 <View style={styles.ctaSlot}>
323 <Tap label={`${promo.cta}: ${promo.title.replace('\n', ' ')}`} onPress={onShop} to={0.94}>
324 <View style={[styles.cta, { backgroundColor: promo.pill }]}>
325 <Text style={[styles.ctaLabel, { color: promo.pillInk }]}>{promo.cta}</Text>
326 <ArrowRight size={14} color={promo.pillInk} strokeWidth={2.6} />
327 </View>
328 </Tap>
329 </View>
330 </View>
331
332 <Animated.View
333 pointerEvents="none"
334 style={[styles.frame, drift]}
335 >
336 <Photo uri={promo.image} alt={promo.alt} width={FRAME - 6} height={FRAME - 6} ratio={promo.ratio} focus={promo.focus} zoom={promo.zoom} tint="#F1F1F1" />
337 </Animated.View>
338 </View>
339 </View>
340 );
341}
342
343function Dot({ index, x, width, color }: { index: number; x: SharedValue<number>; width: number; color: string }) {
344 const style = useAnimatedStyle(() => {
345 const t = Math.max(0, 1 - Math.abs(x.value / width - index));
346 return { width: 6 + t * 14, opacity: 0.22 + t * 0.78 };
347 });
348 return <Animated.View style={[styles.dot, { backgroundColor: color }, style]} />;
349}
350
351function Promos({ onShop, pal }: { onShop: (c: Category) => void; pal: Palette }) {
352 const { width } = useWindowDimensions();
353 const x = useSharedValue(0);
354 const onScroll = useAnimatedScrollHandler((e) => {
355 x.value = e.contentOffset.x;
356 });
357 return (
358 <View>
359 <Animated.ScrollView horizontal pagingEnabled showsHorizontalScrollIndicator={false} onScroll={onScroll} scrollEventThrottle={16} aria-label="Offers">
360 {PROMOS.map((p, i) => (
361 <Banner key={p.id} promo={p} index={i} x={x} width={width} onShop={() => onShop(p.goTo)} />
362 ))}
363 </Animated.ScrollView>
364 <View style={styles.dots}>
365 {PROMOS.map((p, i) => (
366 <Dot key={p.id} index={i} x={x} width={width} color={pal.fg} />
367 ))}
368 </View>
369 </View>
370 );
371}
372
373// ─── Product tile ───────────────────────────────────────────────────────────
374
375const MOVE = LinearTransition.duration(300);
376
377function HeartButton({ liked, onPress, name, accent }: { liked: boolean; onPress: () => void; name: string; accent: string }) {
378 const scale = useSharedValue(1);
379 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
380 return (
381 <Pressable
382 role="button"
383 aria-label={liked ? `Remove ${name} from saved` : `Save ${name}`}
384 hitSlop={6}
385 onPress={() => {
386 scale.value = pop(1.4);
387 onPress();
388 }}
389 style={styles.heart}
390 >
391 <Animated.View style={style}>
392 <Heart size={17} color={liked ? accent : INK} fill={liked ? accent : 'transparent'} strokeWidth={2.2} />
393 </Animated.View>
394 </Pressable>
395 );
396}
397
398function AddButton({ onPress, name, top }: { onPress: () => void; name: string; top: number }) {
399 const [added, setAdded] = useState(false);
400 const scale = useSharedValue(1);
401 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
402 useEffect(() => {
403 if (!added) return;
404 const t = setTimeout(() => setAdded(false), 1100);
405 return () => clearTimeout(t);
406 }, [added]);
407 return (
408 <Pressable
409 role="button"
410 aria-label={`Add ${name} to bag`}
411 hitSlop={6}
412 onPress={() => {
413 scale.value = pop(1.3);
414 setAdded(true);
415 onPress();
416 }}
417 style={[styles.addSlot, { top }]}
418 >
419 <Animated.View style={[styles.add, { backgroundColor: added ? ADDED : INK }, style]}>
420 <Animated.View key={added ? 'added' : 'add'} entering={ZoomIn.duration(160)}>
421 {added ? <Check size={18} color="#FFFFFF" strokeWidth={3} /> : <Plus size={19} color="#FFFFFF" strokeWidth={2.6} />}
422 </Animated.View>
423 </Animated.View>
424 </Pressable>
425 );
426}
427
428function ProductTile({ product, width, liked, onLike, onAdd, intro, pal }: { product: Product; width: number; liked: boolean; onLike: () => void; onAdd: () => void; intro: number | null; pal: Palette }) {
429 const height = Math.round(width * 1.15);
430 const scale = useSharedValue(1);
431 const press = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
432 const off = product.was ? Math.round((1 - product.price / product.was) * 100) : 0;
433 const tag = off ? `−${off}%` : product.isNew ? 'New' : null;
434 return (
435 <Animated.View
436 layout={MOVE}
437 // Staggered on first load; items that a filter brings back simply zoom in.
438 entering={intro === null ? ZoomIn.duration(260) : FadeInDown.delay(180 + intro * 55).duration(420)}
439 exiting={ZoomOut.duration(200)}
440 style={{ width }}
441 >
442 <Animated.View style={press}>
443 {/* Open the product from here. The heart and quick-add sit beside it, not inside it. */}
444 <Pressable
445 role="link"
446 aria-label={`${product.name}, ${product.finish}, $${product.price}`}
447 onPressIn={() => (scale.value = withSpring(0.965, SPRING))}
448 onPressOut={() => (scale.value = withSpring(1, SPRING))}
449 >
450 <View style={styles.tileMedia}>
451 <Photo uri={product.image} alt={`${product.name} in ${product.finish.toLowerCase()}`} width={width} height={height} ratio={product.ratio} focus={product.focus} tint={product.tint} />
452 {/* A hairline keeps white studio shots from melting into the light background. */}
453 <View pointerEvents="none" style={[StyleSheet.absoluteFill, styles.tileEdge, { borderColor: pal.tileEdge }]} />
454 </View>
455 <View style={styles.tileInfo}>
456 <Text numberOfLines={1} style={[styles.tileName, { color: pal.fg }]}>
457 {product.name}
458 </Text>
459 <Text numberOfLines={1} style={[styles.tileMeta, { color: pal.muted }]}>
460 {product.category} · {product.finish}
461 </Text>
462 <View style={styles.tileRow}>
463 <View style={styles.prices}>
464 <Text style={[styles.price, { color: product.was ? pal.accent : pal.fg }, styles.tabular]}>${product.price}</Text>
465 {product.was ? <Text style={[styles.was, { color: pal.faint }, styles.tabular]}>${product.was}</Text> : null}
466 </View>
467 <View style={styles.rating} aria-label={`Rated ${product.rating} from ${product.reviews} reviews`}>
468 <Star size={12} color={STAR} fill={STAR} />
469 <Text style={[styles.ratingText, { color: pal.fg }, styles.tabular]}>{product.rating.toFixed(1)}</Text>
470 </View>
471 </View>
472 </View>
473 </Pressable>
474
475 {tag ? (
476 <View pointerEvents="none" style={[styles.tag, { backgroundColor: off ? pal.accent : INK }]}>
477 <Text style={[styles.tagText, styles.tabular, off ? { color: ON_ACCENT } : null]}>{tag}</Text>
478 </View>
479 ) : null}
480 <HeartButton liked={liked} onPress={onLike} name={product.name} accent={ACCENT} />
481 <AddButton onPress={onAdd} name={product.name} top={height - 46} />
482 </Animated.View>
483 </Animated.View>
484 );
485}
486
487// ─── Tab bar ────────────────────────────────────────────────────────────────
488
489function TabBar({ bag, onSearch, pal }: { bag: number; onSearch: () => void; pal: Palette }) {
490 const insets = useSafeAreaInsets();
491 const [tab, setTab] = useState('Home');
492 return (
493 <View role="tablist" style={[styles.tabBar, { paddingBottom: insets.bottom, backgroundColor: pal.bg, borderTopColor: pal.line }]}>
494 {TABS.map(({ label, icon: Icon }) => {
495 const on = tab === label;
496 return (
497 <Pressable
498 key={label}
499 role="tab"
500 aria-selected={on}
501 aria-label={label === 'Bag' ? `Bag, ${bag} items` : `${label} tab`}
502 onPress={() => {
503 setTab(label);
504 if (label === 'Search') onSearch();
505 }}
506 style={styles.tab}
507 >
508 <View>
509 <Icon size={23} color={on ? pal.fg : pal.muted} strokeWidth={on ? 2.4 : 1.9} />
510 {label === 'Bag' && bag > 0 ? <CountBadge count={bag} ring={pal.bg} color={pal.accent} /> : null}
511 </View>
512 <Text style={[styles.tabLabel, { fontWeight: on ? '700' : '500', color: on ? pal.fg : pal.muted }]}>{label}</Text>
513 </Pressable>
514 );
515 })}
516 </View>
517 );
518}
519
520// ─── Screen ─────────────────────────────────────────────────────────────────
521
522export default function ProductGridScreen() {
523 const pal = usePalette();
524 const insets = useSafeAreaInsets();
525 const { width } = useWindowDimensions();
526 const tile = (width - 40 - 12) / 2;
527
528 const [query, setQuery] = useState('');
529 const [filter, setFilter] = useState<Filter>('All');
530 const [sort, setSort] = useState(0);
531 const [saved, setSaved] = useState<string[]>(['overear']);
532 const [bag, setBag] = useState(2);
533 const inputRef = useRef<ComponentRef<typeof TextInput>>(null);
534 const chipsRef = useRef<ComponentRef<typeof ScrollView>>(null);
535 const chipX = useRef<Record<string, number>>({});
536
537 // Tiles stagger in once; anything a filter adds after that animates on its own.
538 const [settled, setSettled] = useState(false);
539 useEffect(() => {
540 const t = setTimeout(() => setSettled(true), 1200);
541 return () => clearTimeout(t);
542 }, []);
543
544 const term = query.trim().toLowerCase();
545 const visible = useMemo(() => {
546 const list = PRODUCTS.filter((p) => (filter === 'All' || p.category === filter) && p.name.toLowerCase().includes(term));
547 const key = SORTS[sort].key;
548 return key === 'featured' ? list : [...list].sort((a, b) => (key === 'low' ? a.price - b.price : b.price - a.price));
549 }, [filter, term, sort]);
550
551 const pick = (f: Filter) => {
552 setFilter(f);
553 chipsRef.current?.scrollTo({ x: Math.max(0, (chipX.current[f] ?? 0) - 96), animated: true });
554 };
555 const toggleSaved = (id: string) => setSaved((s) => (s.includes(id) ? s.filter((v) => v !== id) : [...s, id]));
556
557 const scrollY = useSharedValue(0);
558 const onScroll = useAnimatedScrollHandler((e) => {
559 scrollY.value = e.contentOffset.y;
560 });
561 // The header's hairline appears once content scrolls under it.
562 const hairline = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [0, 20], [0, 1], 'clamp') }));
563
564 return (
565 <View style={[styles.screen, { backgroundColor: pal.bg }]}>
566 <Animated.ScrollView
567 onScroll={onScroll}
568 scrollEventThrottle={16}
569 showsVerticalScrollIndicator={false}
570 keyboardShouldPersistTaps="handled"
571 contentContainerStyle={{ paddingTop: insets.top + HEADER_H, paddingBottom: insets.bottom + TAB_H + 24 }}
572 >
573 {/* Categories */}
574 <Animated.View entering={FadeInDown.duration(400)}>
575 <ScrollView ref={chipsRef} horizontal showsHorizontalScrollIndicator={false} role="tablist" aria-label="Categories" contentContainerStyle={styles.chips}>
576 {FILTERS.map((f) => (
577 <Chip key={f} label={f} selected={f === filter} onPress={() => pick(f)} onMeasure={(x) => (chipX.current[f] = x)} pal={pal} />
578 ))}
579 </ScrollView>
580 </Animated.View>
581
582 <Animated.View entering={FadeInDown.delay(70).duration(420)}>
583 <Promos onShop={pick} pal={pal} />
584 </Animated.View>
585
586 {/* Section title and sort */}
587 <Animated.View entering={FadeInDown.delay(140).duration(420)} style={styles.sectionHead}>
588 <Text style={[styles.sectionTitle, { color: pal.fg }]}>Popular right now</Text>
589 <Pressable role="button" aria-label={`Sort by ${SORTS[sort].label}. Tap to change.`} hitSlop={10} onPress={() => setSort((s) => (s + 1) % SORTS.length)} style={styles.sort}>
590 <Animated.Text key={sort} entering={FadeInDown.duration(200)} style={[styles.sortLabel, { color: sort ? pal.fg : pal.muted }]}>
591 {SORTS[sort].label}
592 </Animated.Text>
593 <ChevronDown size={15} color={sort ? pal.fg : pal.muted} strokeWidth={2.4} />
594 </Pressable>
595 </Animated.View>
596
597 {/* Grid */}
598 {visible.length > 0 ? (
599 <View style={styles.grid}>
600 {visible.map((p) => (
601 <ProductTile
602 key={p.id}
603 product={p}
604 width={tile}
605 liked={saved.includes(p.id)}
606 onLike={() => toggleSaved(p.id)}
607 onAdd={() => setBag((b) => b + 1)}
608 intro={settled ? null : PRODUCTS.indexOf(p)}
609 pal={pal}
610 />
611 ))}
612 </View>
613 ) : (
614 <Animated.View entering={FadeIn.delay(180).duration(260)} style={styles.empty}>
615 <View style={[styles.emptyIcon, { backgroundColor: pal.chip }]}>
616 <SearchX size={26} color={pal.muted} />
617 </View>
618 <Text numberOfLines={2} style={[styles.emptyTitle, { color: pal.fg }]}>
619 No results for “{query.trim()}”
620 </Text>
621 <Text style={[styles.emptyBody, { color: pal.muted }]}>
622 {filter === 'All' ? 'Check the spelling, or try a shorter word.' : `Nothing in ${filter} matches. Try another category or a shorter word.`}
623 </Text>
624 <Pressable role="link" aria-label="Clear search and show everything" hitSlop={10} onPress={() => setQuery('')} style={styles.emptyAction}>
625 <Text style={[styles.emptyActionLabel, { color: pal.accent }]}>Clear search</Text>
626 </Pressable>
627 </Animated.View>
628 )}
629 </Animated.ScrollView>
630
631 {/* Header: opaque, over the content and under the status bar */}
632 <View style={[styles.header, { paddingTop: insets.top, backgroundColor: pal.bg }]}>
633 <View style={styles.headerBody}>
634 <View style={styles.headerRow}>
635 <View>
636 <Text style={[styles.greeting, { color: pal.muted }]}>Good morning, {SHOPPER}</Text>
637 <Text style={[styles.store, { color: pal.fg }]}>{APP_NAME}</Text>
638 </View>
639 <Tap label={`Bag, ${bag} items`}>
640 <View style={[styles.bagButton, { backgroundColor: pal.chip }]}>
641 <View>
642 <ShoppingBag size={20} color={pal.fg} strokeWidth={2.1} />
643 <CountBadge count={bag} ring={pal.chip} color={pal.accent} />
644 </View>
645 </View>
646 </Tap>
647 </View>
648 <View style={styles.searchSlot}>
649 <SearchField value={query} onChange={setQuery} inputRef={inputRef} pal={pal} />
650 </View>
651 </View>
652 <Animated.View style={[styles.hairline, { backgroundColor: pal.line }, hairline]} />
653 </View>
654
655 <TabBar bag={bag} onSearch={() => inputRef.current?.focus()} pal={pal} />
656 </View>
657 );
658}
659
660// ─── Styles ─────────────────────────────────────────────────────────────────
661
662const styles = StyleSheet.create({
663 screen: { flex: 1 },
664 tabular: { fontVariant: ['tabular-nums'] },
665
666 // Small pieces
667 photo: { overflow: 'hidden' },
668 photoFlash: { backgroundColor: '#FFFFFF' },
669 photoFrame: { position: 'absolute' },
670 badge: { position: 'absolute', top: -6, right: -8, minWidth: 19, height: 19, borderRadius: 10, paddingHorizontal: 4, borderWidth: 2, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' },
671 badgeText: { color: ON_ACCENT, fontSize: 10, fontWeight: '800', lineHeight: 13 },
672
673 // Search field and category chips
674 search: { height: 46, borderRadius: 15, borderWidth: 1.5, flexDirection: 'row', alignItems: 'center', paddingLeft: 13, paddingRight: 8, gap: 9 },
675 searchInput: { flex: 1, height: '100%', fontSize: 16, paddingVertical: 0 },
676 searchClear: { width: 26, height: 26, borderRadius: 13, alignItems: 'center', justifyContent: 'center' },
677 chips: { paddingHorizontal: 20, paddingTop: 6, gap: 8 },
678 chip: { height: 38, paddingHorizontal: 16, borderRadius: 19, justifyContent: 'center' },
679 chipFill: { borderRadius: 19 },
680 chipLabel: { fontSize: 14.5, fontWeight: '600' },
681
682 // Promo carousel
683 banner: { paddingHorizontal: 20, paddingTop: BREAKOUT },
684 bannerCard: { height: BANNER_H, borderRadius: 28 },
685 bannerFill: { borderRadius: 28, overflow: 'hidden' },
686 rings: { position: 'absolute', right: -70, top: -50 },
687 bannerBody: { flex: 1, paddingLeft: 20, justifyContent: 'center', alignItems: 'flex-start' },
688 eyebrow: { opacity: 0.8, fontSize: 11, fontWeight: '700', letterSpacing: 1.3, textTransform: 'uppercase' },
689 bannerTitle: { fontSize: 26, lineHeight: 29, fontWeight: '800', letterSpacing: -0.9, marginTop: 5 },
690 ctaSlot: { marginTop: 12 },
691 cta: { height: 32, paddingLeft: 14, paddingRight: 11, borderRadius: 16, flexDirection: 'row', alignItems: 'center', gap: 5 },
692 ctaLabel: { fontSize: 13, fontWeight: '700' },
693 frame: {
694 position: 'absolute',
695 right: 16,
696 top: -16,
697 width: FRAME,
698 height: FRAME,
699 borderRadius: 26,
700 borderWidth: 3,
701 borderColor: '#FFFFFF',
702 overflow: 'hidden',
703 backgroundColor: '#F1F1F1',
704 shadowColor: '#000',
705 shadowOpacity: 0.28,
706 shadowRadius: 18,
707 shadowOffset: { width: 0, height: 10 },
708 },
709 dots: { flexDirection: 'row', justifyContent: 'center', gap: 6, marginTop: 12 },
710 dot: { height: 6, borderRadius: 3 },
711
712 // Product tile
713 heart: {
714 position: 'absolute',
715 top: 10,
716 right: 10,
717 width: 34,
718 height: 34,
719 borderRadius: 17,
720 backgroundColor: 'rgba(255,255,255,0.94)',
721 alignItems: 'center',
722 justifyContent: 'center',
723 shadowColor: '#000',
724 shadowOpacity: 0.12,
725 shadowRadius: 6,
726 shadowOffset: { width: 0, height: 2 },
727 },
728 addSlot: { position: 'absolute', right: 10 },
729 add: { width: 36, height: 36, borderRadius: 18, alignItems: 'center', justifyContent: 'center', shadowColor: '#000', shadowOpacity: 0.2, shadowRadius: 8, shadowOffset: { width: 0, height: 3 } },
730 tileMedia: { borderRadius: 24, overflow: 'hidden' },
731 tileEdge: { borderRadius: 24, borderWidth: 1 },
732 tileInfo: { paddingHorizontal: 4, paddingTop: 10 },
733 tileName: { fontSize: 15.5, fontWeight: '600', letterSpacing: -0.2 },
734 tileMeta: { fontSize: 13, marginTop: 2 },
735 tileRow: { flexDirection: 'row', alignItems: 'center', marginTop: 7 },
736 prices: { flex: 1, flexDirection: 'row', alignItems: 'baseline', gap: 6 },
737 price: { fontSize: 16, fontWeight: '700', letterSpacing: -0.2 },
738 was: { fontSize: 13, textDecorationLine: 'line-through' },
739 rating: { flexDirection: 'row', alignItems: 'center', gap: 3 },
740 ratingText: { fontSize: 12.5, fontWeight: '600' },
741 tag: { position: 'absolute', top: 12, left: 12, height: 24, paddingHorizontal: 9, borderRadius: 12, justifyContent: 'center' },
742 tagText: { color: '#FFFFFF', fontSize: 11.5, fontWeight: '700', letterSpacing: 0.2 },
743
744 // Tab bar
745 tabBar: { position: 'absolute', left: 0, right: 0, bottom: 0, borderTopWidth: 1, flexDirection: 'row' },
746 tab: { flex: 1, height: TAB_H, alignItems: 'center', justifyContent: 'center', gap: 4 },
747 tabLabel: { fontSize: 10.5 },
748
749 // Screen
750 sectionHead: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 20, marginTop: 20 },
751 sectionTitle: { fontSize: 20, fontWeight: '700', letterSpacing: -0.5 },
752 sort: { flexDirection: 'row', alignItems: 'center', gap: 3, height: 28 },
753 sortLabel: { fontSize: 13.5, fontWeight: '600' },
754 grid: { flexDirection: 'row', flexWrap: 'wrap', columnGap: 12, rowGap: 22, paddingHorizontal: 20, marginTop: 14 },
755 empty: { alignItems: 'center', paddingHorizontal: 36, paddingTop: 36, paddingBottom: 12 },
756 emptyIcon: { width: 64, height: 64, borderRadius: 32, alignItems: 'center', justifyContent: 'center' },
757 emptyTitle: { fontSize: 19, fontWeight: '700', letterSpacing: -0.4, textAlign: 'center', marginTop: 16 },
758 emptyBody: { fontSize: 14.5, lineHeight: 21, textAlign: 'center', marginTop: 6 },
759 emptyAction: { marginTop: 16 },
760 emptyActionLabel: { fontSize: 15, fontWeight: '700' },
761 header: { position: 'absolute', top: 0, left: 0, right: 0 },
762 headerBody: { height: HEADER_H, paddingHorizontal: 20 },
763 headerRow: { height: 56, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
764 greeting: { fontSize: 13 },
765 store: { fontSize: 25, fontWeight: '800', letterSpacing: -0.9, marginTop: 1 },
766 bagButton: { width: 44, height: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center' },
767 searchSlot: { marginTop: 4 },
768 hairline: { height: 1 },
769});

More screens like this.

All Commerce