User profile

Photo-led public profile driven by one scroll handler: the cover drifts in parallax, stretches when pulled and darkens into a compact bar with a small avatar and name, while the icon tabs pin beneath it. Follow morphs into an outlined Following as the follower count rolls up a digit, and a sliding indicator switches between a photo grid, reels and tagged photos that fade in over tinted placeholders.

profilefollowstatsphoto gridtabsparallaxcollapsing-headersticky-tabsanimationreanimated
Paste into Claude Code Cursor Codex Lovable RapidNative
Live preview · follows the site themeOpen full screen

Details

File
components/patterns/user-profile.tsx
Lines
826
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/user-profile.tsx
1import { useEffect, useRef, useState, type ComponentRef, type ReactNode } from 'react';
2import { Image, Pressable, ScrollView, StyleSheet, Text, View, useColorScheme, useWindowDimensions, type LayoutChangeEvent, type StyleProp, type ViewStyle } from 'react-native';
3import Animated, {
4 cancelAnimation,
5 Easing,
6 FadeIn,
7 FadeInDown,
8 interpolate,
9 interpolateColor,
10 runOnJS,
11 useAnimatedReaction,
12 useAnimatedScrollHandler,
13 useAnimatedStyle,
14 useSharedValue,
15 withRepeat,
16 withSequence,
17 withSpring,
18 withTiming,
19 type SharedValue,
20} from 'react-native-reanimated';
21import { LinearGradient } from 'expo-linear-gradient';
22import { useSafeAreaInsets } from 'react-native-safe-area-context';
23import {
24 BadgeCheck,
25 Bell,
26 BellRing,
27 CalendarDays,
28 Check,
29 ChevronLeft,
30 Clapperboard,
31 Ellipsis,
32 Grid3x3,
33 Images,
34 MapPin,
35 Play,
36 SquareUserRound,
37 type LucideIcon,
38} from 'lucide-react-native';
39
40// ─── Brand ──────────────────────────────────────────────────────────────────
41// The screen's accent. Every accent colour below derives from these, so changing them rebrands the screen.
42
43const ACCENT = '#1064FF';
44const ACCENT_DARK = '#5B97FF'; // the accent as text on dark backgrounds
45const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
46
47/** `hex` at `alpha` opacity, as rgba(). */
48function tint(hex: string, alpha: number) {
49 const n = parseInt(hex.slice(1), 16);
50 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
51}
52
53// ─── Sample data ────────────────────────────────────────────────────────────
54
55const photo = (id: string, w: number, h?: number) => `https://images.unsplash.com/photo-${id}?w=${w}${h ? `&h=${h}` : ''}&q=80&fit=crop`;
56
57const USER = {
58 name: 'Sofia Martinez',
59 handle: '@sofiaoutdoors',
60 avatar: '1494790108377-be9c29b29330',
61 bio: 'Chasing first light across the Alps. Spring workshops are now open at',
62 link: 'sofiamartinez.photo',
63 place: 'Lisbon, Portugal',
64 joined: 'Joined March 2019',
65 posts: 248,
66 followers: 18429,
67 following: 312,
68};
69
70// Each shot carries its own placeholder tint, so the grid reads as a blurred preview while it loads.
71const SHOTS = {
72 ridge: { id: '1506905925346-21bda4d32df4', alt: 'Peaks above a sea of cloud at dusk', tint: '#5B6788' },
73 moraine: { id: '1493246507139-91e8fad9978e', alt: 'Moraine Lake under a pink sunrise', tint: '#7C6A7C' },
74 valley: { id: '1464822759023-fed622ff2c3b', alt: 'Pine valley below a blue mountain range', tint: '#4F7A8C' },
75 stars: { id: '1519681393784-d120267933ba', alt: 'Milky Way over a snowy ridge', tint: '#2B2F5E' },
76 summit: { id: '1454496522488-7a8e488e8606', alt: 'Snow covered summit in cloud', tint: '#A9B7CC' },
77 braies: { id: '1501785888041-af3ef285b470', alt: 'Wooden boat on a turquoise alpine lake', tint: '#3E9AA0' },
78 pass: { id: '1470071459604-3b5ec3a7fe05', alt: 'Green mountain pass at sunrise', tint: '#6F7F4E' },
79 bowl: { id: '1546069901-ba9599a7e63c', alt: 'Salmon and vegetable lunch bowl', tint: '#D8D2C4' },
80 plant: { id: '1485955900006-10f4d324d411', alt: 'Succulent in a mint green pot', tint: '#DDE5E2' },
81 camera: { id: '1516035069371-29a1b244cc32', alt: 'Camera body with two lenses', tint: '#26262A' },
82 instant: { id: '1526170375885-4d8ecf77b99f', alt: 'Instant camera on a grey table', tint: '#D5D5D7' },
83 sofa: { id: '1555041469-a586c61ea9bc', alt: 'Green velvet sofa in a bright studio', tint: '#C9C2B4' },
84 sofia: { id: '1494790108377-be9c29b29330', alt: 'Sofia laughing in a red jumper', tint: '#8E6E66' },
85} as const;
86type ShotKey = keyof typeof SHOTS;
87
88const COVER: ShotKey = 'ridge';
89
90const HIGHLIGHTS: { label: string; shot: ShotKey }[] = [
91 { label: 'Dolomites', shot: 'valley' },
92 { label: 'Night sky', shot: 'stars' },
93 { label: 'Gear', shot: 'camera' },
94 { label: 'Lakes', shot: 'braies' },
95 { label: 'Studio', shot: 'sofa' },
96 { label: 'Eats', shot: 'bowl' },
97];
98
99// `detail` reuses a shot as a tight crop of its centre.
100const POSTS: { shot: ShotKey; mark?: 'set' | 'reel'; detail?: boolean }[] = [
101 { shot: 'moraine', mark: 'set' },
102 { shot: 'camera' },
103 { shot: 'braies' },
104 { shot: 'bowl' },
105 { shot: 'valley', mark: 'reel' },
106 { shot: 'plant' },
107 { shot: 'stars', mark: 'set' },
108 { shot: 'sofa' },
109 { shot: 'summit', detail: true },
110 { shot: 'pass' },
111 { shot: 'instant' },
112 { shot: 'camera', detail: true },
113 { shot: 'summit', mark: 'reel' },
114 { shot: 'bowl', detail: true },
115 { shot: 'ridge' },
116 { shot: 'braies', detail: true },
117 { shot: 'stars', mark: 'reel', detail: true },
118 { shot: 'pass', detail: true },
119];
120
121const REELS: { shot: ShotKey; views: string; length: string }[] = [
122 { shot: 'stars', views: '128K', length: '0:42' },
123 { shot: 'braies', views: '48.2K', length: '0:18' },
124 { shot: 'valley', views: '36.9K', length: '1:04' },
125 { shot: 'moraine', views: '21.4K', length: '0:27' },
126 { shot: 'pass', views: '17.8K', length: '0:51' },
127 { shot: 'summit', views: '9,204', length: '0:33' },
128];
129
130const FRIENDS = {
131 priya: { handle: 'priya.k', avatar: '1438761681033-6461ffad8d80' },
132 elena: { handle: 'elena.voss', avatar: '1544005313-94ddf0286df2' },
133 mika: { handle: 'mika.tanaka', avatar: '1534528741775-53994a69daeb' },
134} as const;
135
136// The first one is the large tile.
137const TAGGED: { shot: ShotKey; by: keyof typeof FRIENDS }[] = [
138 { shot: 'sofia', by: 'priya' },
139 { shot: 'camera', by: 'mika' },
140 { shot: 'instant', by: 'elena' },
141 { shot: 'ridge', by: 'mika' },
142 { shot: 'sofa', by: 'priya' },
143 { shot: 'bowl', by: 'elena' },
144 { shot: 'valley', by: 'priya' },
145 { shot: 'stars', by: 'mika' },
146 { shot: 'moraine', by: 'elena' },
147];
148
149const TABS = [
150 { key: 'posts', label: 'Posts', icon: Grid3x3 },
151 { key: 'reels', label: 'Reels', icon: Clapperboard },
152 { key: 'tagged', label: 'Tagged', icon: SquareUserRound },
153] as const;
154type TabKey = (typeof TABS)[number]['key'];
155
156// ─── Palette ────────────────────────────────────────────────────────────────
157
158const SPRING = { damping: 20, stiffness: 240, mass: 0.7 };
159const POP = { damping: 14, stiffness: 300, mass: 0.6 };
160const TABULAR = { fontVariant: ['tabular-nums' as const] };
161const comma = (n: number) => n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
162
163const COVER_BODY = 160; // cover height below the status bar
164const BAR = 44;
165const TAB_H = 46;
166const AVATAR = 96;
167const PARALLAX = 0.45;
168const GAP = 2;
169
170function usePalette() {
171 const dark = useColorScheme() === 'dark';
172 return {
173 dark,
174 bg: dark ? '#000000' : '#FFFFFF',
175 fg: dark ? '#FAFAFA' : '#0A0A0A',
176 muted: dark ? '#8E8E93' : '#6E6E76',
177 line: dark ? '#232327' : '#E8E8EB',
178 edge: dark ? '#3A3A40' : '#D4D4DA',
179 chip: dark ? '#1C1C1F' : '#F1F1F3',
180 link: dark ? ACCENT_DARK : ACCENT,
181 alertsOn: dark ? tint(ACCENT, 0.2) : tint(ACCENT, 0.1),
182 };
183}
184
185const enter = (delay: number) => FadeInDown.delay(delay).duration(420);
186
187// ─── Small pieces ───────────────────────────────────────────────────────────
188
189function Tap({ children, label, onPress, to = 0.94, style }: { children: ReactNode; label: string; onPress?: () => void; to?: number; style?: StyleProp<ViewStyle> }) {
190 const scale = useSharedValue(1);
191 const pressed = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
192 return (
193 <Pressable
194 role="button"
195 aria-label={label}
196 onPress={onPress}
197 hitSlop={6}
198 onPressIn={() => (scale.value = withSpring(to, POP))}
199 onPressOut={() => (scale.value = withSpring(1, POP))}
200 style={style}
201 >
202 <Animated.View style={pressed}>{children}</Animated.View>
203 </Pressable>
204 );
205}
206
207/** A photo that fades in over its own tint, which shimmers until the image arrives. */
208function Photo({ shot, w, h, style }: { shot: ShotKey; w: number; h?: number; style?: StyleProp<ViewStyle> }) {
209 const s = SHOTS[shot];
210 const shown = useSharedValue(0);
211 const pulse = useSharedValue(0);
212 useEffect(() => {
213 pulse.value = withRepeat(withSequence(withTiming(1, { duration: 700 }), withTiming(0, { duration: 700 })), -1);
214 return () => cancelAnimation(pulse);
215 }, [pulse]);
216 const image = useAnimatedStyle(() => ({ opacity: shown.value }));
217 const sheen = useAnimatedStyle(() => ({ opacity: (1 - shown.value) * pulse.value * 0.2 }));
218 return (
219 <View style={[styles.photo, { backgroundColor: s.tint }, style]}>
220 <Animated.View style={[StyleSheet.absoluteFill, styles.photoSheen, sheen]} />
221 <Animated.View style={[StyleSheet.absoluteFill, image]}>
222 <Image
223 source={{ uri: photo(s.id, w, h) }}
224 alt={s.alt}
225 resizeMode="cover"
226 style={styles.photoImage}
227 onLoad={() => {
228 cancelAnimation(pulse);
229 shown.value = withTiming(1, { duration: 320 });
230 }}
231 />
232 </Animated.View>
233 </View>
234 );
235}
236
237// ─── Animated number: each digit rolls on its own strip ─────────────────────
238
239const DIGIT_H = 26;
240
241function Digit({ value, dir, color }: { value: number; dir: number; color: string }) {
242 const pos = useSharedValue(value);
243 const last = useRef(value);
244 useEffect(() => {
245 const from = last.current;
246 last.current = value;
247 if (from === value) return;
248 const roll = { duration: 420, easing: Easing.out(Easing.cubic) };
249 // The strip ends with a second 0, so 9 to 0 keeps rolling forward and 0 to 9 rolls back.
250 if (dir > 0 && value < from) pos.value = withSequence(withTiming(10, roll), withTiming(value, { duration: 0 }));
251 else if (dir < 0 && value > from) pos.value = withSequence(withTiming(10, { duration: 0 }), withTiming(value, roll));
252 else pos.value = withTiming(value, roll);
253 }, [value, dir, pos]);
254 const strip = useAnimatedStyle(() => ({ transform: [{ translateY: -pos.value * DIGIT_H }] }));
255 return (
256 <View style={styles.digitClip}>
257 <Animated.View style={strip}>
258 {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0].map((d, i) => (
259 <Text key={i} style={[styles.number, TABULAR, styles.digit, { color }]}>
260 {d}
261 </Text>
262 ))}
263 </Animated.View>
264 </View>
265 );
266}
267
268function Ticker({ value, color }: { value: number; color: string }) {
269 const last = useRef(value);
270 const dir = value >= last.current ? 1 : -1;
271 useEffect(() => {
272 last.current = value;
273 }, [value]);
274 const chars = comma(value).split('');
275 return (
276 <View role="img" aria-label={comma(value)} style={styles.ticker}>
277 {chars.map((ch, i) =>
278 ch === ',' ? (
279 <Text key={`c${chars.length - i}`} style={[styles.number, { color }]}>
280 ,
281 </Text>
282 ) : (
283 <Digit key={chars.length - i} value={Number(ch)} dir={dir} color={color} />
284 )
285 )}
286 </View>
287 );
288}
289
290function Stat({ label, children }: { label: string; children: ReactNode }) {
291 const c = usePalette();
292 return (
293 <View style={styles.stat}>
294 {children}
295 <Text style={[styles.statLabel, { color: c.muted }]}>{label}</Text>
296 </View>
297 );
298}
299
300// ─── Cover: parallax, stretch on pull, darkens as it collapses ──────────────
301
302function Cover({ scrollY, height, travel, scrim, decorative }: { scrollY: SharedValue<number>; height: number; travel: number; scrim: number; decorative?: boolean }) {
303 const motion = useAnimatedStyle(() => {
304 const y = scrollY.value;
305 // Pulled down, it grows from the top edge. Scrolled up, it drifts at under half speed, then holds.
306 const pull = Math.max(0, -y);
307 return {
308 transform: [{ translateY: pull / 2 - Math.min(Math.max(0, y), travel) * PARALLAX }, { scale: 1 + pull / height }],
309 };
310 });
311 const shade = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [0, travel], [0, 0.64], 'clamp') }));
312 return (
313 <Animated.View aria-hidden={decorative} style={[styles.cover, { height }, motion]}>
314 <Photo shot={COVER} w={900} style={StyleSheet.absoluteFill} />
315 {/* Keeps the white status bar readable over any photo. */}
316 <LinearGradient pointerEvents="none" colors={['rgba(0,0,0,0.6)', 'rgba(0,0,0,0)']} style={[styles.coverScrim, { height: scrim }]} />
317 <Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, styles.coverShade, shade]} />
318 </Animated.View>
319 );
320}
321
322function BarButton({ icon: Icon, label, scrollY, travel }: { icon: LucideIcon; label: string; scrollY: SharedValue<number>; travel: number }) {
323 // The dark circle is only needed over the open photo; it melts into the bar once that has darkened.
324 const circle = useAnimatedStyle(() => ({ opacity: interpolate(scrollY.value, [travel - 40, travel], [1, 0], 'clamp') }));
325 return (
326 <Tap label={label} to={0.88}>
327 <View style={styles.barButton}>
328 <Animated.View style={[StyleSheet.absoluteFill, styles.barButtonCircle, circle]} />
329 {/* Wrapped so the glyph paints above the circle on web. */}
330 <View>
331 <Icon size={21} color="#FFFFFF" strokeWidth={2.4} />
332 </View>
333 </View>
334 </Tap>
335 );
336}
337
338// ─── Actions ────────────────────────────────────────────────────────────────
339
340function FollowButton({ following, onToggle, wide, narrow }: { following: boolean; onToggle: () => void; wide: number; narrow: number }) {
341 const c = usePalette();
342 const p = useSharedValue(following ? 1 : 0);
343 const w = useSharedValue(following ? narrow : wide);
344 const press = useSharedValue(1);
345 useEffect(() => {
346 p.value = withTiming(following ? 1 : 0, { duration: 260, easing: Easing.out(Easing.cubic) });
347 w.value = withSpring(following ? narrow : wide, SPRING);
348 }, [following, narrow, wide, p, w]);
349 // Filled accent when you can follow, a quiet outline once you do; the button gives up width to Message.
350 const box = useAnimatedStyle(() => ({
351 width: w.value,
352 backgroundColor: interpolateColor(p.value, [0, 1], [ACCENT, c.bg]),
353 borderColor: interpolateColor(p.value, [0, 1], [ACCENT, c.edge]),
354 transform: [{ scale: press.value }],
355 }));
356 const off = useAnimatedStyle(() => ({ opacity: 1 - p.value, transform: [{ translateY: -12 * p.value }] }));
357 const on = useAnimatedStyle(() => ({ opacity: p.value, transform: [{ translateY: 12 * (1 - p.value) }] }));
358 const layer = [StyleSheet.absoluteFill, styles.followLayer] as const;
359 return (
360 <Pressable
361 role="button"
362 aria-label={following ? `Following ${USER.name}. Tap to unfollow` : `Follow ${USER.name}`}
363 onPress={onToggle}
364 onPressIn={() => (press.value = withSpring(0.96, POP))}
365 onPressOut={() => (press.value = withSpring(1, POP))}
366 >
367 <Animated.View style={[styles.follow, box]}>
368 <Animated.View style={[layer, off]}>
369 <Text style={[styles.followLabel, styles.followLabelOn]}>Follow</Text>
370 </Animated.View>
371 <Animated.View style={[layer, on]}>
372 <Check size={16} color={c.fg} strokeWidth={3} />
373 <Text style={[styles.followLabel, { color: c.fg }]}>Following</Text>
374 </Animated.View>
375 </Animated.View>
376 </Pressable>
377 );
378}
379
380function AlertsButton({ on, onToggle }: { on: boolean; onToggle: () => void }) {
381 const c = usePalette();
382 const swing = useSharedValue(0);
383 const style = useAnimatedStyle(() => ({ transform: [{ rotate: `${swing.value}deg` }] }));
384 const Icon = on ? BellRing : Bell;
385 return (
386 <Pressable
387 role="switch"
388 aria-checked={on}
389 aria-label="Post notifications"
390 onPress={() => {
391 onToggle();
392 // The bell rings once when alerts are switched on.
393 if (!on) swing.value = withSequence(withTiming(-18, { duration: 70 }), withTiming(15, { duration: 90 }), withTiming(-9, { duration: 90 }), withTiming(0, { duration: 90 }));
394 }}
395 style={({ pressed }) => [styles.alerts, { backgroundColor: on ? c.alertsOn : c.chip, opacity: pressed ? 0.7 : 1 }]}
396 >
397 <Animated.View style={style}>
398 <Icon size={19} color={on ? c.link : c.fg} strokeWidth={2.2} />
399 </Animated.View>
400 </Pressable>
401 );
402}
403
404// ─── Tabs: icons with a bar that slides between them ────────────────────────
405
406function Tabs({ tab, onChange, x, width }: { tab: TabKey; onChange: (t: TabKey) => void; x: SharedValue<number>; width: number }) {
407 const c = usePalette();
408 const slot = width / TABS.length;
409 const bar = useAnimatedStyle(() => ({ transform: [{ translateX: (x.value + 0.5) * slot - 24 }] }));
410 return (
411 <View role="tablist" style={[styles.tabs, { backgroundColor: c.bg, borderBottomColor: c.line }]}>
412 {TABS.map((t) => {
413 const selected = t.key === tab;
414 const Icon = t.icon;
415 return (
416 <Pressable key={t.key} role="tab" aria-label={t.label} aria-selected={selected} onPress={() => onChange(t.key)} style={styles.tab}>
417 <Icon size={23} color={selected ? c.fg : c.muted} strokeWidth={selected ? 2.3 : 1.9} />
418 </Pressable>
419 );
420 })}
421 <Animated.View style={[styles.tabBar, { backgroundColor: c.fg }, bar]} />
422 </View>
423 );
424}
425
426// ─── Tab content ────────────────────────────────────────────────────────────
427
428const rows = <T,>(items: readonly T[], per: number) => Array.from({ length: Math.ceil(items.length / per) }, (_, i) => items.slice(i * per, i * per + per));
429
430/** A pressable photo tile. Push the post or reel from onPress. */
431function Tile({ shot, label, w, h, style, children }: { shot: ShotKey; label: string; w: number; h: number; style: StyleProp<ViewStyle>; children?: ReactNode }) {
432 return (
433 <Pressable role="button" aria-label={label} style={({ pressed }) => [style, { opacity: pressed ? 0.82 : 1 }]}>
434 <Photo shot={shot} w={w} h={h} style={StyleSheet.absoluteFill} />
435 {children}
436 </Pressable>
437 );
438}
439
440function PostGrid({ width }: { width: number }) {
441 const size = Math.round((width - GAP * 2) / 3);
442 return (
443 <View style={styles.grid}>
444 {rows(POSTS, 3).map((row, r) => (
445 <View key={r} style={styles.gridRow}>
446 {row.map((p) => {
447 const Mark = p.mark === 'set' ? Images : Clapperboard;
448 return (
449 <Tile key={`${p.shot}${p.detail ? '-detail' : ''}`} shot={p.shot} label={`Post: ${SHOTS[p.shot].alt}${p.detail ? ', close up' : ''}`} w={300} h={p.detail ? 900 : 300} style={[styles.tile, { height: size }]}>
450 {p.mark ? (
451 <View style={styles.postMark}>
452 <Mark size={17} color="#FFFFFF" strokeWidth={2.4} />
453 </View>
454 ) : null}
455 </Tile>
456 );
457 })}
458 </View>
459 ))}
460 </View>
461 );
462}
463
464function ReelGrid({ width }: { width: number }) {
465 const height = Math.round(((width - GAP) / 2) * 1.32);
466 return (
467 <View style={styles.grid}>
468 {rows(REELS, 2).map((row, r) => (
469 <View key={r} style={styles.gridRow}>
470 {row.map((reel) => (
471 <Tile key={reel.shot} shot={reel.shot} label={`Reel: ${SHOTS[reel.shot].alt}, ${reel.views} views`} w={400} h={528} style={[styles.tile, { height }]}>
472 <LinearGradient pointerEvents="none" colors={['rgba(0,0,0,0)', 'rgba(0,0,0,0.62)']} style={styles.reelShade} />
473 <View style={styles.reelLength}>
474 <Text style={[styles.reelLengthText, TABULAR]}>{reel.length}</Text>
475 </View>
476 <View style={styles.reelViews}>
477 <Play size={13} color="#FFFFFF" fill="#FFFFFF" />
478 <Text style={[styles.reelViewsText, TABULAR]}>{reel.views}</Text>
479 </View>
480 </Tile>
481 ))}
482 </View>
483 ))}
484 </View>
485 );
486}
487
488function TaggedTile({ item, style, large }: { item: (typeof TAGGED)[number]; style: StyleProp<ViewStyle>; large?: boolean }) {
489 const friend = FRIENDS[item.by];
490 return (
491 <Tile shot={item.shot} label={`Tagged by ${friend.handle}: ${SHOTS[item.shot].alt}`} w={large ? 600 : 300} h={large ? 600 : 300} style={style}>
492 <LinearGradient pointerEvents="none" colors={['rgba(0,0,0,0)', 'rgba(0,0,0,0.6)']} style={[styles.taggedShade, { height: large ? 72 : 52 }]} />
493 <View style={[styles.taggedBy, { left: large ? 11 : 7, bottom: large ? 10 : 7 }]}>
494 <Image source={{ uri: photo(friend.avatar, 80, 80) }} alt="" style={[styles.taggedAvatar, { width: large ? 24 : 18, height: large ? 24 : 18 }]} />
495 <Text numberOfLines={1} style={[styles.taggedHandle, { fontSize: large ? 13.5 : 11.5 }]}>
496 {friend.handle}
497 </Text>
498 </View>
499 </Tile>
500 );
501}
502
503function TaggedGrid({ width }: { width: number }) {
504 const c = usePalette();
505 const small = Math.floor((width - GAP * 2) / 3);
506 const [lead, a, b, ...rest] = TAGGED;
507 return (
508 <View style={styles.grid}>
509 {/* One large tile beside two stacked ones, then regular rows. */}
510 <View style={[styles.gridRow, { height: small * 2 + GAP }]}>
511 <TaggedTile item={lead} large style={styles.tile} />
512 <View style={[styles.grid, { width: small }]}>
513 <TaggedTile item={a} style={styles.tile} />
514 <TaggedTile item={b} style={styles.tile} />
515 </View>
516 </View>
517 {rows(rest, 3).map((row, r) => (
518 <View key={r} style={styles.gridRow}>
519 {row.map((item) => (
520 <TaggedTile key={item.shot} item={item} style={[styles.tile, { height: small }]} />
521 ))}
522 </View>
523 ))}
524 <Text style={[styles.taggedNote, { color: c.muted }]}>
525 Photos appear here once Sofia approves the tag.
526 </Text>
527 </View>
528 );
529}
530
531// ─── Screen ─────────────────────────────────────────────────────────────────
532
533export default function UserProfileScreen() {
534 const c = usePalette();
535 const insets = useSafeAreaInsets();
536 const { width, height } = useWindowDimensions();
537 const coverH = insets.top + COVER_BODY;
538 const navH = insets.top + BAR;
539 const travel = coverH - navH; // how far the cover collapses before it becomes the bar
540
541 // Replace with your profile query; persist follow and alerts through your API.
542 const [following, setFollowing] = useState(false);
543 const [alerts, setAlerts] = useState(false);
544 const [tab, setTab] = useState<TabKey>('posts');
545 const [pinned, setPinned] = useState(false);
546 const [linkHeld, setLinkHeld] = useState(false);
547
548 // One scroll position drives the cover, the avatar, the compact bar and the pinned tabs.
549 const scrollRef = useRef<ComponentRef<typeof ScrollView>>(null);
550 const pinAt = useRef(0);
551 const scrollY = useSharedValue(0);
552 const tabsY = useSharedValue(100000);
553 const onScroll = useAnimatedScrollHandler((e) => {
554 scrollY.value = e.contentOffset.y;
555 });
556 useAnimatedReaction(
557 () => scrollY.value >= tabsY.value - navH,
558 (now, before) => {
559 if (now !== before) runOnJS(setPinned)(now);
560 }
561 );
562
563 const index = TABS.findIndex((t) => t.key === tab);
564 const tabX = useSharedValue(index);
565 useEffect(() => {
566 tabX.value = withSpring(index, SPRING);
567 }, [index, tabX]);
568 const selectTab = (next: TabKey) => {
569 if (next === tab) return;
570 setTab(next);
571 // With the tabs pinned, every tab opens at its own top.
572 if (pinned) scrollRef.current?.scrollTo({ y: pinAt.current, animated: false });
573 };
574
575 // The avatar shrinks toward its bottom left corner, then slides under the bar.
576 const avatar = useAnimatedStyle(() => {
577 const s = interpolate(scrollY.value, [0, travel], [1, 0.6], 'clamp');
578 return { transform: [{ translateX: (-(1 - s) * AVATAR) / 2 }, { translateY: ((1 - s) * AVATAR) / 2 }, { scale: s }] };
579 });
580 // The bar's avatar and name arrive as the large name passes under it.
581 const barTitle = useAnimatedStyle(() => ({
582 opacity: interpolate(scrollY.value, [travel + 58, travel + 90], [0, 1], 'clamp'),
583 transform: [{ translateY: interpolate(scrollY.value, [travel + 58, travel + 90], [10, 0], 'clamp') }],
584 }));
585 const pinnedTabs = useAnimatedStyle(() => ({ opacity: scrollY.value >= tabsY.value - navH ? 1 : 0 }));
586
587 const flexible = width - 32 - 44 - 16;
588 const followers = USER.followers + (following ? 1 : 0);
589
590 return (
591 <View style={[styles.screen, { backgroundColor: c.bg }]}>
592 <Cover scrollY={scrollY} height={coverH} travel={travel} scrim={insets.top + 56} />
593
594 <Animated.ScrollView ref={scrollRef} onScroll={onScroll} scrollEventThrottle={16} showsVerticalScrollIndicator={false}>
595 {/* A window onto the cover, which sits behind the list. */}
596 <View style={{ height: coverH }} />
597
598 <View style={{ backgroundColor: c.bg }}>
599 {/* Avatar and stats */}
600 <View style={styles.identity}>
601 <Animated.View entering={FadeIn.duration(360)}>
602 <Animated.View style={[styles.avatarRing, { backgroundColor: c.bg }, avatar]}>
603 <Image
604 source={{ uri: photo(USER.avatar, 300, 300) }}
605 alt={USER.name}
606 style={styles.avatar}
607 />
608 <View aria-label="Verified" style={[styles.verified, { backgroundColor: c.bg }]}>
609 <BadgeCheck size={25} color={c.bg} fill={ACCENT} strokeWidth={2.2} />
610 </View>
611 </Animated.View>
612 </Animated.View>
613 <Animated.View entering={enter(40)} style={styles.stats}>
614 <Stat label="Posts">
615 <Text style={[styles.number, TABULAR, { color: c.fg }]}>{comma(USER.posts)}</Text>
616 </Stat>
617 <Stat label="Followers">
618 <Ticker value={followers} color={c.fg} />
619 </Stat>
620 <Stat label="Following">
621 <Text style={[styles.number, TABULAR, { color: c.fg }]}>{comma(USER.following)}</Text>
622 </Stat>
623 </Animated.View>
624 </View>
625
626 {/* Name, bio and details */}
627 <Animated.View entering={enter(90)} style={styles.about}>
628 <Text role="heading" style={[styles.name, { color: c.fg }]}>
629 {USER.name}
630 </Text>
631 <Text style={[styles.handle, { color: c.muted }]}>{USER.handle}</Text>
632 <Text style={[styles.bio, { color: c.fg }]}>
633 {USER.bio}{' '}
634 {/* Open the link with Linking.openURL. */}
635 <Text
636 role="link"
637 aria-label={`Open ${USER.link}`}
638 onPress={() => {}}
639 onPressIn={() => setLinkHeld(true)}
640 onPressOut={() => setLinkHeld(false)}
641 style={[styles.link, { color: c.link, opacity: linkHeld ? 0.5 : 1 }]}
642 >
643 {USER.link}
644 </Text>
645 </Text>
646 <View style={styles.details}>
647 <MapPin size={14} color={c.muted} strokeWidth={2.1} />
648 <Text style={[styles.detail, styles.detailPlace, { color: c.muted }]}>{USER.place}</Text>
649 <CalendarDays size={14} color={c.muted} strokeWidth={2.1} />
650 <Text style={[styles.detail, { color: c.muted }]}>{USER.joined}</Text>
651 </View>
652 </Animated.View>
653
654 {/* Actions */}
655 <Animated.View entering={enter(140)} style={styles.actions}>
656 <FollowButton following={following} onToggle={() => setFollowing((f) => !f)} wide={Math.round(flexible * 0.6)} narrow={Math.round(flexible * 0.47)} />
657 {/* Open the conversation from onPress. */}
658 <Tap label={`Message ${USER.name}`} to={0.96} style={styles.messageSlot}>
659 <View style={[styles.message, { backgroundColor: c.chip }]}>
660 <Text style={[styles.followLabel, { color: c.fg }]}>Message</Text>
661 </View>
662 </Tap>
663 <AlertsButton on={alerts} onToggle={() => setAlerts((a) => !a)} />
664 </Animated.View>
665
666 {/* Highlights */}
667 <Animated.View entering={enter(190)}>
668 <ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerStyle={styles.highlights}>
669 {HIGHLIGHTS.map((h) => (
670 <Tap key={h.label} label={`${h.label} highlight`}>
671 <View style={styles.highlight}>
672 <View style={[styles.highlightRing, { borderColor: c.edge }]}>
673 <Photo shot={h.shot} w={160} h={160} style={styles.highlightPhoto} />
674 </View>
675 <Text numberOfLines={1} style={[styles.highlightLabel, { color: c.fg }]}>
676 {h.label}
677 </Text>
678 </View>
679 </Tap>
680 ))}
681 </ScrollView>
682 </Animated.View>
683
684 {/* Tabs in the flow; a pinned copy takes over when these reach the bar. */}
685 <View
686 onLayout={(e: LayoutChangeEvent) => {
687 const y = coverH + e.nativeEvent.layout.y;
688 tabsY.value = y;
689 pinAt.current = y - navH;
690 }}
691 >
692 <Animated.View entering={enter(240)}>
693 <Tabs tab={tab} onChange={selectTab} x={tabX} width={width} />
694 </Animated.View>
695 </View>
696
697 {/* Tall enough for the tabs to pin whichever tab is open. */}
698 <Animated.View entering={enter(280)} style={[styles.tabContent, { minHeight: height - navH - TAB_H, paddingBottom: insets.bottom + 24 }]}>
699 <Animated.View key={tab} entering={FadeIn.duration(260)}>
700 {tab === 'posts' ? <PostGrid width={width} /> : tab === 'reels' ? <ReelGrid width={width} /> : <TaggedGrid width={width} />}
701 </Animated.View>
702 </Animated.View>
703 </View>
704 </Animated.ScrollView>
705
706 {/* Compact bar: the same cover, clipped to bar height, so the photo itself becomes the header. */}
707 <View pointerEvents="box-none" style={styles.top}>
708 <View style={[styles.bar, { height: navH }]}>
709 <Cover scrollY={scrollY} height={coverH} travel={travel} scrim={insets.top + 56} decorative />
710 <View style={[styles.barRow, { marginTop: insets.top }]}>
711 {/* Go back with your router. */}
712 <BarButton icon={ChevronLeft} label="Back" scrollY={scrollY} travel={travel} />
713 <Animated.View pointerEvents="none" style={[styles.barTitle, barTitle]}>
714 <Image source={{ uri: photo(USER.avatar, 300, 300) }} alt="" style={styles.barAvatar} />
715 <View style={styles.barText}>
716 <View style={styles.barNameRow}>
717 <Text numberOfLines={1} style={styles.barName}>
718 {USER.name}
719 </Text>
720 <BadgeCheck size={15} color="#101014" fill="#FFFFFF" strokeWidth={2.4} />
721 </View>
722 <Text numberOfLines={1} style={styles.barSub}>
723 {comma(USER.posts)} posts
724 </Text>
725 </View>
726 </Animated.View>
727 {/* Open your share, mute and report sheet. */}
728 <BarButton icon={Ellipsis} label="More options" scrollY={scrollY} travel={travel} />
729 </View>
730 </View>
731 <Animated.View pointerEvents={pinned ? 'auto' : 'none'} aria-hidden={!pinned} style={pinnedTabs}>
732 <Tabs tab={tab} onChange={selectTab} x={tabX} width={width} />
733 </Animated.View>
734 </View>
735 </View>
736 );
737}
738
739// ─── Styles ─────────────────────────────────────────────────────────────────
740
741const styles = StyleSheet.create({
742 screen: { flex: 1 },
743
744 // Photos and numbers
745 photo: { overflow: 'hidden' },
746 photoSheen: { backgroundColor: '#FFFFFF' },
747 photoImage: { width: '100%', height: '100%' },
748 number: { fontSize: 21, lineHeight: DIGIT_H, fontWeight: '800', letterSpacing: -0.4 },
749 digitClip: { height: DIGIT_H, overflow: 'hidden' },
750 digit: { height: DIGIT_H },
751 ticker: { flexDirection: 'row' },
752 stat: { flex: 1, alignItems: 'center' },
753 statLabel: { fontSize: 13, marginTop: 1 },
754
755 // Cover and compact bar
756 cover: { position: 'absolute', top: 0, left: 0, right: 0 },
757 coverScrim: { position: 'absolute', top: 0, left: 0, right: 0 },
758 coverShade: { backgroundColor: '#000000' },
759 top: { position: 'absolute', top: 0, left: 0, right: 0 },
760 bar: { overflow: 'hidden' },
761 barRow: { height: BAR, flexDirection: 'row', alignItems: 'center', gap: 10, paddingHorizontal: 12 },
762 barButton: { width: 36, height: 36, alignItems: 'center', justifyContent: 'center' },
763 barButtonCircle: { borderRadius: 18, backgroundColor: 'rgba(0,0,0,0.42)' },
764 barTitle: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 9 },
765 barAvatar: { width: 30, height: 30, borderRadius: 15, borderWidth: 1, borderColor: 'rgba(255,255,255,0.7)', backgroundColor: SHOTS.sofia.tint },
766 barText: { flex: 1 },
767 barNameRow: { flexDirection: 'row', alignItems: 'center', gap: 4 },
768 barName: { flexShrink: 1, color: '#FFFFFF', fontSize: 16, fontWeight: '700', letterSpacing: -0.2 },
769 barSub: { color: 'rgba(255,255,255,0.72)', fontSize: 12.5, marginTop: -1 },
770
771 // Identity
772 identity: { flexDirection: 'row', alignItems: 'flex-end', paddingHorizontal: 16, marginTop: -AVATAR / 2 },
773 avatarRing: { width: AVATAR, height: AVATAR, borderRadius: AVATAR / 2, alignItems: 'center', justifyContent: 'center' },
774 avatar: { width: AVATAR - 8, height: AVATAR - 8, borderRadius: (AVATAR - 8) / 2, backgroundColor: SHOTS.sofia.tint },
775 verified: { position: 'absolute', right: 0, bottom: 2, width: 28, height: 28, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
776 stats: { flex: 1, flexDirection: 'row', marginLeft: 18, paddingBottom: 1 },
777 about: { paddingHorizontal: 16, marginTop: 12 },
778 name: { fontSize: 24, lineHeight: 29, fontWeight: '800', letterSpacing: -0.6 },
779 handle: { fontSize: 15, marginTop: 1 },
780 bio: { fontSize: 15, lineHeight: 21, marginTop: 10 },
781 link: { fontWeight: '600' },
782 details: { flexDirection: 'row', alignItems: 'center', gap: 5, marginTop: 9 },
783 detail: { fontSize: 13.5 },
784 detailPlace: { marginRight: 9 },
785
786 // Actions
787 actions: { flexDirection: 'row', gap: 8, paddingHorizontal: 16, marginTop: 16 },
788 follow: { height: 44, borderRadius: 14, borderWidth: 1.5, overflow: 'hidden' },
789 followLayer: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6 },
790 followLabel: { fontSize: 15.5, fontWeight: '700' },
791 followLabelOn: { color: ON_ACCENT },
792 messageSlot: { flex: 1 },
793 message: { height: 44, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
794 alerts: { width: 44, height: 44, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
795
796 // Highlights
797 highlights: { paddingHorizontal: 14, paddingTop: 20, paddingBottom: 14, gap: 10 },
798 highlight: { width: 68, alignItems: 'center' },
799 highlightRing: { width: 66, height: 66, borderRadius: 33, borderWidth: 1.5, alignItems: 'center', justifyContent: 'center' },
800 highlightPhoto: { width: 57, height: 57, borderRadius: 29 },
801 highlightLabel: { fontSize: 12, marginTop: 6 },
802
803 // Tabs
804 tabs: { height: TAB_H, flexDirection: 'row', borderBottomWidth: 1 },
805 tab: { flex: 1, alignItems: 'center', justifyContent: 'center' },
806 tabBar: { position: 'absolute', left: 0, bottom: -1, width: 48, height: 2.5, borderRadius: 2 },
807 tabContent: { paddingTop: GAP },
808
809 // Grids
810 grid: { gap: GAP },
811 gridRow: { flexDirection: 'row', gap: GAP },
812 tile: { flex: 1 },
813 // A shadow's props stay together in one style object: React Native Web builds the shadow per object.
814 postMark: { position: 'absolute', top: 7, right: 7, shadowColor: '#000', shadowOpacity: 0.5, shadowRadius: 4, shadowOffset: { width: 0, height: 1 } },
815 reelShade: { position: 'absolute', left: 0, right: 0, bottom: 0, height: 84 },
816 reelLength: { position: 'absolute', top: 9, right: 9, height: 22, paddingHorizontal: 7, borderRadius: 11, justifyContent: 'center', backgroundColor: 'rgba(0,0,0,0.5)' },
817 reelLengthText: { color: '#FFFFFF', fontSize: 11.5, fontWeight: '600' },
818 reelViews: { position: 'absolute', left: 11, bottom: 10, flexDirection: 'row', alignItems: 'center', gap: 5 },
819 reelViewsText: { color: '#FFFFFF', fontSize: 14, fontWeight: '700' },
820 taggedShade: { position: 'absolute', left: 0, right: 0, bottom: 0 },
821 taggedBy: { position: 'absolute', right: 7, flexDirection: 'row', alignItems: 'center', gap: 5 },
822 taggedAvatar: { borderRadius: 12, borderWidth: 1, borderColor: 'rgba(255,255,255,0.85)', backgroundColor: '#8884' },
823 taggedHandle: { flexShrink: 1, color: '#FFFFFF', fontWeight: '600' },
824 taggedNote: { fontSize: 13, textAlign: 'center', marginTop: 22, marginHorizontal: 40, lineHeight: 18 },
825});

More screens like this.

All Social & Feeds