Notification permission

Explain-then-ask screen where three notification cards drop in under a ringing bell with a counting badge, and animated switches let people pick what they get, dimming the matching card. The primary button opens a drawn system alert: Allow morphs the bell into a tick, Don't Allow leaves a gentle Settings hint.

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

Details

File
components/patterns/notification-permission.tsx
Lines
787
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/notification-permission.tsx
1import { useEffect, useState } from 'react';
2import { Pressable, ScrollView, StyleSheet, Text, View, useColorScheme, useWindowDimensions, type LayoutChangeEvent } from 'react-native';
3import Animated, {
4 Easing,
5 FadeIn,
6 FadeInDown,
7 ZoomIn,
8 interpolate,
9 interpolateColor,
10 useAnimatedStyle,
11 useSharedValue,
12 withDelay,
13 withRepeat,
14 withSequence,
15 withSpring,
16 withTiming,
17} from 'react-native-reanimated';
18import { LinearGradient } from 'expo-linear-gradient';
19import { useSafeAreaInsets } from 'react-native-safe-area-context';
20import Svg, { Defs, RadialGradient, Rect, Stop } from 'react-native-svg';
21import { Bell, BellRing, Check, Lock, MessageCircle, Newspaper, Package, Settings, type LucideIcon } from 'lucide-react-native';
22
23// ─── Brand ──────────────────────────────────────────────────────────────────
24// The app's accent and name. Every accent colour below derives from these, so changing them rebrands the screen.
25
26const ACCENT = '#F2541B';
27const ACCENT_DARK = '#FF6B35'; // the accent on dark backgrounds
28const ON_ACCENT = '#FFFFFF'; // text and icons on an accent fill
29const APP_NAME = 'Parcel';
30
31/** `hex` at `alpha` opacity, as rgba(). */
32function tint(hex: string, alpha: number) {
33 const n = parseInt(hex.slice(1), 16);
34 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
35}
36
37/** `hex` mixed toward black (amount > 0) or white (amount < 0); amount from -1 to 1. */
38function shade(hex: string, amount: number) {
39 const n = parseInt(hex.slice(1), 16);
40 const target = amount < 0 ? 255 : 0;
41 const p = Math.abs(amount);
42 const c = (v: number) => Math.round(v + (target - v) * p).toString(16).padStart(2, '0');
43 return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`.toUpperCase();
44}
45
46/** `hex` with its hue turned by `deg` and its lightness and saturation moved by `light` and `sat` (HSL, -1 to 1), for colours that run warmer, cooler or brighter than the accent. */
47function spin(hex: string, deg: number, light = 0, sat = 0) {
48 const n = parseInt(hex.slice(1), 16);
49 const r = ((n >> 16) & 255) / 255;
50 const g = ((n >> 8) & 255) / 255;
51 const b = (n & 255) / 255;
52 const max = Math.max(r, g, b);
53 const min = Math.min(r, g, b);
54 const d = max - min;
55 const s = Math.min(1, Math.max(0, (d === 0 ? 0 : d / (1 - Math.abs(max + min - 1))) + sat));
56 const l = Math.min(1, Math.max(0, (max + min) / 2 + light));
57 const h0 = d === 0 ? 0 : max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
58 const h = (((h0 * 60 + deg) % 360) + 360) % 360;
59 const a = s * Math.min(l, 1 - l);
60 const f = (m: number) => {
61 const k = (m + h / 30) % 12;
62 return Math.round(255 * (l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)))).toString(16).padStart(2, '0');
63 };
64 return `#${f(0)}${f(8)}${f(4)}`.toUpperCase();
65}
66
67// ─── Sample data ────────────────────────────────────────────────────────────
68
69const STEP = { current: 3, total: 4 };
70
71type KindKey = 'orders' | 'messages' | 'digest';
72
73type Kind = {
74 key: KindKey;
75 icon: LucideIcon;
76 label: string;
77 detail: string;
78 /** Whether the switch starts on. */
79 on: boolean;
80 tile: readonly [string, string];
81 tint: { light: string; dark: string };
82 preview: { title: string; body: string; time: string };
83};
84
85// Each kind is one switch in the list and one notification card in the illustration.
86const KINDS: Kind[] = [
87 {
88 key: 'orders',
89 icon: Package,
90 label: 'Order updates',
91 detail: 'Shipped, on its way, delivered',
92 on: true,
93 tile: ['#FF9A5C', '#F2541B'],
94 tint: { light: '#F2541B', dark: '#FF8A5C' },
95 preview: { title: 'Out for delivery', body: 'Pour-over set arrives by 2:40 pm', time: 'now' },
96 },
97 {
98 key: 'messages',
99 icon: MessageCircle,
100 label: 'Messages',
101 detail: 'From couriers and sellers',
102 on: true,
103 tile: ['#5CB0FF', '#2F6BFF'],
104 tint: { light: '#2F6BFF', dark: '#6FA8FF' },
105 preview: { title: 'Dario, your courier', body: "I'm downstairs, buzzer 4B is out", time: '2m ago' },
106 },
107 {
108 key: 'digest',
109 icon: Newspaper,
110 label: 'Weekly digest',
111 detail: 'Monday recap of your orders',
112 on: false,
113 tile: ['#5EEAD4', '#0D9488'],
114 tint: { light: '#0D9488', dark: '#2DD4BF' },
115 preview: { title: 'Your week in parcels', body: '3 delivered, 1 on the way', time: 'Mon' },
116 },
117];
118
119const COPY = {
120 title: "Don't miss what matters",
121 body: 'Know the moment an order moves.\nYou choose what gets through.',
122 doneTitle: "You're all set",
123 privacy: 'We only send what you pick. Change it anytime.',
124 later: 'No problem. Turn these on later in Settings.',
125 alertTitle: `“${APP_NAME}” Would Like to Send You Notifications`,
126 alertBody: 'Notifications may include alerts, sounds and icon badges. These can be configured in Settings.',
127};
128
129// "order updates", "order updates and messages", "order updates, messages and weekly digest"
130const listOf = (names: string[]) => (names.length < 2 ? names.join('') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`);
131
132// ─── Palette ────────────────────────────────────────────────────────────────
133
134const SPRING = { damping: 16, stiffness: 220, mass: 0.7 };
135const TABULAR = { fontVariant: ['tabular-nums' as const] };
136
137function usePalette() {
138 const dark = useColorScheme() === 'dark';
139 return {
140 dark,
141 accent: dark ? ACCENT_DARK : ACCENT,
142 // Button fill: deep enough in both themes for white text.
143 fill: ACCENT,
144 accentTile: (dark ? [shade(ACCENT_DARK, -0.18), ACCENT] : [shade(ACCENT_DARK, -0.125), spin(ACCENT, 0, -0.05, 0.01)]) as readonly [string, string],
145 success: dark ? '#22C55E' : '#16A34A',
146 successTile: ['#4ADE80', '#16A34A'] as readonly [string, string],
147 bg: dark ? '#0C0A09' : '#FBF8F6',
148 wash: dark ? shade(ACCENT, 0.75) : shade(ACCENT, -0.81),
149 bloom: dark ? shade(ACCENT, -0.04) : shade(ACCENT, -0.36),
150 card: dark ? '#1C1917' : '#FFFFFF',
151 edge: dark ? 'rgba(255,255,255,0.09)' : 'rgba(22,17,14,0.05)',
152 fg: dark ? '#FAF7F5' : '#16110E',
153 muted: dark ? '#A1968E' : '#756B65',
154 faint: dark ? '#6B625C' : '#A89F99',
155 line: dark ? '#2A2522' : '#EFE9E4',
156 track: dark ? '#3A3430' : '#E2DBD5',
157 hint: dark ? tint(ACCENT_DARK, 0.14) : tint(ACCENT, 0.09),
158 badge: dark ? '#FFFFFF' : '#16110E',
159 badgeFg: dark ? '#16110E' : '#FFFFFF',
160 // The drawn system alert keeps the platform's own greys and blue.
161 alert: dark ? '#2A2A2C' : '#F4F4F5',
162 alertFg: dark ? '#FFFFFF' : '#000000',
163 alertLine: dark ? 'rgba(84,84,88,0.65)' : 'rgba(60,60,67,0.22)',
164 alertPress: dark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.07)',
165 alertBlue: dark ? '#0A84FF' : '#007AFF',
166 scrim: dark ? 'rgba(0,0,0,0.6)' : 'rgba(0,0,0,0.42)',
167 cardShadow: dark ? '#000' : shade(ACCENT, 0.5),
168 stepTodo: dark ? 'rgba(255,255,255,0.18)' : 'rgba(22,17,14,0.12)',
169 };
170}
171
172// ─── Layout ─────────────────────────────────────────────────────────────────
173
174const HEADER_H = 44;
175const STAGE = { w: 342, h: 240 };
176const BELL = 56;
177const CARD = { w: 304, h: 58, top: 52, pitch: 64 };
178// A slightly fanned stack reads as a pile of cards, not a list.
179const SLOTS = [
180 { x: -7, tilt: -2 },
181 { x: 9, tilt: 1.6 },
182 { x: -3, tilt: -1 },
183];
184// Card i starts dropping at DROP.delay + i * DROP.gap and touches down about DROP.land later.
185const DROP = { delay: 120, gap: 180, duration: 460, land: 260 };
186
187// ─── Backdrop: an accent wash under the status bar and a glow behind the stack ─
188
189function Backdrop({ width }: { width: number }) {
190 const c = usePalette();
191 const size = 460;
192 return (
193 <View pointerEvents="none" style={StyleSheet.absoluteFill}>
194 <LinearGradient colors={[c.wash, c.bg]} style={styles.wash} />
195 <View style={[styles.bloom, { left: (width - size) / 2, width: size, height: size }]}>
196 <Svg width={size} height={size}>
197 <Defs>
198 <RadialGradient id="permission-bloom" cx="50%" cy="50%" r="50%">
199 <Stop offset="0" stopColor={c.bloom} stopOpacity={c.dark ? 0.42 : 0.5} />
200 <Stop offset="1" stopColor={c.bloom} stopOpacity={0} />
201 </RadialGradient>
202 </Defs>
203 <Rect width={size} height={size} fill="url(#permission-bloom)" />
204 </Svg>
205 </View>
206 </View>
207 );
208}
209
210// ─── Bell: rings as each card lands, counts them, and turns into a tick ─────
211
212function HeroBell({ count, ringKey, granted }: { count: number; ringKey: number; granted: boolean }) {
213 const c = usePalette();
214 const swing = useSharedValue(0);
215 const badge = useSharedValue(0);
216 const ripple = useSharedValue(1);
217 const ok = useSharedValue(0);
218 const float = useSharedValue(0);
219
220 useEffect(() => {
221 float.value = withRepeat(withTiming(1, { duration: 3200, easing: Easing.inOut(Easing.sin) }), -1, true);
222 }, [float]);
223
224 useEffect(() => {
225 if (ringKey === 0) return;
226 swing.value = withSequence(
227 withTiming(-16, { duration: 70 }),
228 withTiming(13, { duration: 90 }),
229 withTiming(-8, { duration: 90 }),
230 withTiming(5, { duration: 80 }),
231 withTiming(0, { duration: 70 })
232 );
233 ripple.value = withSequence(withTiming(0, { duration: 0 }), withTiming(1, { duration: 620, easing: Easing.out(Easing.cubic) }));
234 }, [ringKey, ripple, swing]);
235
236 useEffect(() => {
237 badge.value =
238 count > 0 && !granted
239 ? withSequence(withTiming(1.32, { duration: 110 }), withTiming(1, { duration: 200, easing: Easing.out(Easing.back(2)) }))
240 : withTiming(0, { duration: 160 });
241 }, [count, ringKey, granted, badge]);
242
243 useEffect(() => {
244 ok.value = withTiming(granted ? 1 : 0, { duration: 300, easing: Easing.out(Easing.back(1.8)) });
245 if (granted) ripple.value = withSequence(withTiming(0, { duration: 0 }), withTiming(1, { duration: 700, easing: Easing.out(Easing.cubic) }));
246 }, [granted, ok, ripple]);
247
248 const floatStyle = useAnimatedStyle(() => ({ transform: [{ translateY: (float.value - 0.5) * 4 }] }));
249 const rippleStyle = useAnimatedStyle(() => ({ opacity: (1 - ripple.value) * 0.55, transform: [{ scale: 1 + ripple.value * 0.85 }] }));
250 const greenStyle = useAnimatedStyle(() => ({ opacity: Math.min(1, Math.max(0, ok.value)) }));
251 const bellStyle = useAnimatedStyle(() => ({
252 opacity: 1 - Math.min(1, Math.max(0, ok.value)),
253 transform: [{ rotate: `${swing.value}deg` }, { scale: 1 - Math.min(1, Math.max(0, ok.value)) * 0.5 }],
254 }));
255 const tickStyle = useAnimatedStyle(() => ({
256 opacity: Math.min(1, Math.max(0, ok.value)),
257 transform: [{ scale: interpolate(ok.value, [0, 1], [0.4, 1]) }],
258 }));
259 const badgeStyle = useAnimatedStyle(() => ({ opacity: Math.min(1, badge.value), transform: [{ scale: badge.value }] }));
260
261 const glow = granted ? c.success : c.accent;
262 return (
263 <Animated.View style={[styles.bell, floatStyle]}>
264 <Animated.View entering={ZoomIn.duration(320)} style={styles.fill}>
265 <Animated.View style={[StyleSheet.absoluteFill, styles.ripple, { borderColor: glow }, rippleStyle]} />
266 <View
267 role="img"
268 aria-label={granted ? 'Notifications are on' : `${count} notification${count === 1 ? '' : 's'} waiting`}
269 style={[styles.bellGlow, { shadowColor: glow, shadowOpacity: 0.45, shadowRadius: 18, shadowOffset: { width: 0, height: 8 } }]}
270 >
271 <View style={styles.bellFace}>
272 <LinearGradient colors={c.accentTile} style={StyleSheet.absoluteFill} />
273 <Animated.View style={[StyleSheet.absoluteFill, greenStyle]}>
274 <LinearGradient colors={c.successTile} style={StyleSheet.absoluteFill} />
275 </Animated.View>
276 <View style={[StyleSheet.absoluteFill, styles.bellSheen]} />
277 <Animated.View style={[styles.bellIcon, bellStyle]}>
278 <Bell size={26} color={ON_ACCENT} fill={ON_ACCENT} strokeWidth={2} />
279 </Animated.View>
280 <Animated.View style={[styles.tick, tickStyle]}>
281 <Check size={28} color="#fff" strokeWidth={3.2} />
282 </Animated.View>
283 </View>
284 </View>
285 <Animated.View style={[styles.badge, { backgroundColor: c.badge }, badgeStyle]}>
286 <Text style={[styles.badgeText, { color: c.badgeFg }, TABULAR]}>{Math.max(count, 1)}</Text>
287 </Animated.View>
288 </Animated.View>
289 </Animated.View>
290 );
291}
292
293// ─── Notification card: drops in with an overshoot, then floats ─────────────
294
295function NotificationCard({ kind, index, on }: { kind: Kind; index: number; on: boolean }) {
296 const c = usePalette();
297 const slot = SLOTS[index];
298 const drop = useSharedValue(0);
299 const float = useSharedValue(0);
300 const lit = useSharedValue(on ? 1 : 0);
301
302 useEffect(() => {
303 drop.value = withDelay(DROP.delay + index * DROP.gap, withTiming(1, { duration: DROP.duration, easing: Easing.out(Easing.back(1.7)) }));
304 float.value = withDelay(index * 300, withRepeat(withTiming(1, { duration: 2800 + index * 420, easing: Easing.inOut(Easing.sin) }), -1, true));
305 }, [drop, float, index]);
306
307 useEffect(() => {
308 lit.value = withTiming(on ? 1 : 0, { duration: 260, easing: Easing.out(Easing.cubic) });
309 }, [on, lit]);
310
311 const style = useAnimatedStyle(() => ({
312 opacity: interpolate(drop.value, [0, 0.35], [0, 1], 'clamp') * interpolate(lit.value, [0, 1], [0.38, 1]),
313 transform: [
314 { translateY: (1 - drop.value) * -44 + (float.value - 0.5) * 5 },
315 { rotate: `${slot.tilt}deg` },
316 { scale: interpolate(drop.value, [0, 1], [0.88, 1]) * interpolate(lit.value, [0, 1], [0.96, 1]) },
317 ],
318 }));
319
320 const Icon = kind.icon;
321 return (
322 <Animated.View
323 role="img"
324 aria-label={`${kind.label} notification: ${kind.preview.title}. ${kind.preview.body}${on ? '' : ' (off)'}`}
325 style={[
326 styles.card,
327 {
328 left: (STAGE.w - CARD.w) / 2 + slot.x,
329 top: CARD.top + index * CARD.pitch,
330 backgroundColor: c.card,
331 borderColor: c.edge,
332 shadowColor: c.cardShadow,
333 shadowOpacity: c.dark ? 0.4 : 0.14,
334 shadowRadius: 18,
335 shadowOffset: { width: 0, height: 9 },
336 },
337 style,
338 ]}
339 >
340 <LinearGradient colors={kind.tile} style={styles.cardTile}>
341 <Icon size={18} color="#fff" strokeWidth={2.2} />
342 </LinearGradient>
343 <View style={styles.fill}>
344 <View style={styles.cardHead}>
345 <Text numberOfLines={1} style={[styles.cardTitle, { color: c.fg }]}>
346 {kind.preview.title}
347 </Text>
348 <Text style={[styles.cardTime, { color: c.faint }, TABULAR]}>{kind.preview.time}</Text>
349 </View>
350 <Text numberOfLines={1} style={[styles.cardBody, { color: c.muted }]}>
351 {kind.preview.body}
352 </Text>
353 </View>
354 </Animated.View>
355 );
356}
357
358// ─── Switch row: the thumb slides and stretches, the track changes colour ───
359
360function KindRow({ kind, on, last, onToggle }: { kind: Kind; on: boolean; last: boolean; onToggle: () => void }) {
361 const c = usePalette();
362 const p = useSharedValue(on ? 1 : 0);
363 useEffect(() => {
364 p.value = withTiming(on ? 1 : 0, { duration: 240, easing: Easing.out(Easing.cubic) });
365 }, [on, p]);
366
367 const track = useAnimatedStyle(() => ({ backgroundColor: interpolateColor(p.value, [0, 1], [c.track, c.accent]) }));
368 const thumb = useAnimatedStyle(() => {
369 // Widest halfway across, so the thumb seems to stretch as it travels.
370 const w = 24 + (1 - Math.abs(2 * p.value - 1)) * 6;
371 return { width: w, transform: [{ translateX: p.value * (44 - w) }] };
372 });
373 const tile = useAnimatedStyle(() => ({ opacity: interpolate(p.value, [0, 1], [0.45, 1]) }));
374
375 const Icon = kind.icon;
376 const tint = c.dark ? kind.tint.dark : kind.tint.light;
377 return (
378 <Pressable
379 role="switch"
380 aria-checked={on}
381 aria-label={kind.label}
382 onPress={onToggle}
383 style={({ pressed }) => [styles.kindRow, { backgroundColor: pressed ? c.line : 'transparent' }]}
384 >
385 <Animated.View style={[styles.kindTile, { backgroundColor: `${tint}24` }, tile]}>
386 <Icon size={18} color={tint} strokeWidth={2.2} />
387 </Animated.View>
388 <View style={styles.fill}>
389 <Text numberOfLines={1} style={[styles.kindLabel, { color: c.fg }]}>
390 {kind.label}
391 </Text>
392 <Text numberOfLines={1} style={[styles.kindDetail, { color: c.muted }]}>
393 {kind.detail}
394 </Text>
395 </View>
396 <Animated.View style={[styles.switchTrack, track]}>
397 <Animated.View style={[styles.switchThumb, thumb]} />
398 </Animated.View>
399 {last ? null : <View style={[styles.kindDivider, { backgroundColor: c.line }]} />}
400 </Pressable>
401 );
402}
403
404// ─── Primary button: press scale, then a tick once permission is granted ────
405
406type ButtonState = 'ready' | 'empty' | 'done';
407
408function PrimaryButton({ state, onPress }: { state: ButtonState; onPress: () => void }) {
409 const c = usePalette();
410 const scale = useSharedValue(1);
411 const style = useAnimatedStyle(() => ({ transform: [{ scale: scale.value }] }));
412 const fill = state === 'done' ? '#16A34A' : state === 'empty' ? c.track : c.fill;
413 // White on the success green once done, the accent's ink while ready.
414 const ink = state === 'empty' ? c.muted : state === 'done' ? '#fff' : ON_ACCENT;
415 const label = state === 'done' ? 'Notifications on' : state === 'empty' ? 'Pick at least one' : 'Turn on notifications';
416 const text = [styles.buttonText, { color: ink }];
417 return (
418 <Pressable
419 role="button"
420 aria-label={label}
421 aria-disabled={state !== 'ready'}
422 disabled={state !== 'ready'}
423 onPress={onPress}
424 onPressIn={() => (scale.value = withSpring(0.96, SPRING))}
425 onPressOut={() => (scale.value = withSpring(1, SPRING))}
426 >
427 <Animated.View
428 style={[
429 styles.button,
430 {
431 backgroundColor: fill,
432 shadowColor: fill,
433 shadowOpacity: state === 'empty' ? 0 : 0.36,
434 shadowRadius: 16,
435 shadowOffset: { width: 0, height: 8 },
436 borderTopColor: state === 'empty' ? 'transparent' : state === 'done' ? 'rgba(255,255,255,0.3)' : tint(ON_ACCENT, 0.3),
437 },
438 style,
439 ]}
440 >
441 {state === 'done' ? (
442 <Animated.View key="done" entering={ZoomIn.springify().damping(13)} style={styles.buttonLabel}>
443 <Check size={20} color={ink} strokeWidth={3} />
444 <Text style={text}>{label}</Text>
445 </Animated.View>
446 ) : (
447 <Animated.View key={state} entering={FadeIn.duration(180)} style={styles.buttonLabel}>
448 {state === 'ready' ? <BellRing size={19} color={ink} strokeWidth={2.4} /> : null}
449 <Text style={text}>{label}</Text>
450 </Animated.View>
451 )}
452 </Animated.View>
453 </Pressable>
454 );
455}
456
457// ─── A drawn copy of the system permission alert ────────────────────────────
458
459function PermissionAlert({ open, onAllow, onDeny }: { open: boolean; onAllow: () => void; onDeny: () => void }) {
460 const c = usePalette();
461 const [mounted, setMounted] = useState(open);
462 const t = useSharedValue(0);
463
464 useEffect(() => {
465 if (open) {
466 setMounted(true);
467 t.value = withTiming(1, { duration: 260, easing: Easing.out(Easing.cubic) });
468 return;
469 }
470 // Stay mounted just long enough to fade out.
471 t.value = withTiming(0, { duration: 160 });
472 const off = setTimeout(() => setMounted(false), 180);
473 return () => clearTimeout(off);
474 }, [open, t]);
475
476 const dim = useAnimatedStyle(() => ({ opacity: t.value }));
477 const box = useAnimatedStyle(() => ({ opacity: t.value, transform: [{ scale: interpolate(t.value, [0, 1], [1.16, 1]) }] }));
478
479 if (!mounted) return null;
480 const action = [styles.alertActionText, { color: c.alertBlue }];
481 return (
482 <View pointerEvents={open ? 'auto' : 'none'} style={[StyleSheet.absoluteFill, styles.alertLayer]}>
483 <Animated.View style={[StyleSheet.absoluteFill, { backgroundColor: c.scrim }, dim]} />
484 <Animated.View
485 role="alertdialog"
486 aria-modal
487 aria-label={COPY.alertTitle}
488 style={[styles.alert, { backgroundColor: c.alert }, box]}
489 >
490 <View style={styles.alertCopy}>
491 <Text style={[styles.alertTitle, { color: c.alertFg }]}>{COPY.alertTitle}</Text>
492 <Text style={[styles.alertBody, { color: c.alertFg }]}>{COPY.alertBody}</Text>
493 </View>
494 <View style={[styles.alertRule, { backgroundColor: c.alertLine }]} />
495 <View style={styles.alertActions}>
496 <Pressable role="button" aria-label="Don't Allow" onPress={onDeny} style={({ pressed }) => [styles.alertAction, { backgroundColor: pressed ? c.alertPress : 'transparent' }]}>
497 <Text style={action}>Don't Allow</Text>
498 </Pressable>
499 <View style={[styles.alertDivider, { backgroundColor: c.alertLine }]} />
500 <Pressable role="button" aria-label="Allow" onPress={onAllow} style={({ pressed }) => [styles.alertAction, { backgroundColor: pressed ? c.alertPress : 'transparent' }]}>
501 <Text style={[action, styles.alertAllow]}>Allow</Text>
502 </Pressable>
503 </View>
504 </Animated.View>
505 </View>
506 );
507}
508
509// ─── Screen ─────────────────────────────────────────────────────────────────
510
511type Phase = 'idle' | 'asking' | 'granted';
512
513export default function NotificationPermissionScreen() {
514 const c = usePalette();
515 const insets = useSafeAreaInsets();
516 const { width } = useWindowDimensions();
517 const [on, setOn] = useState(() => Object.fromEntries(KINDS.map((k) => [k.key, k.on])) as Record<KindKey, boolean>);
518 const [phase, setPhase] = useState<Phase>('idle');
519 const [declined, setDeclined] = useState(false);
520 // How many cards have touched down, and a counter that rings the bell each time it changes.
521 const [landed, setLanded] = useState(0);
522 const [ringKey, setRingKey] = useState(0);
523 const [room, setRoom] = useState(STAGE.h);
524
525 useEffect(() => {
526 const timers = KINDS.map((_, i) =>
527 setTimeout(() => {
528 setLanded(i + 1);
529 setRingKey((k) => k + 1);
530 }, DROP.delay + i * DROP.gap + DROP.land)
531 );
532 return () => timers.forEach(clearTimeout);
533 }, []);
534
535 // The success state holds for a moment, then resets so the preview can replay.
536 useEffect(() => {
537 if (phase !== 'granted') return;
538 const reset = setTimeout(() => setPhase('idle'), 2200);
539 return () => clearTimeout(reset);
540 }, [phase]);
541
542 const picked = KINDS.filter((k) => on[k.key]);
543 const waiting = KINDS.filter((k, i) => on[k.key] && i < landed).length;
544 const granted = phase === 'granted';
545
546 const toggle = (key: KindKey) => {
547 if (!on[key]) setRingKey((k) => k + 1);
548 setOn((s) => ({ ...s, [key]: !s[key] }));
549 };
550 const ask = () => {
551 setDeclined(false);
552 // Replace with your real request, for example expo-notifications requestPermissionsAsync().
553 setPhase('asking');
554 };
555 const allow = () => {
556 // Register the push token and save `picked` as the user's topics here, then navigate on.
557 setPhase('granted');
558 };
559 const deny = () => {
560 setPhase('idle');
561 setDeclined(true);
562 };
563
564 const stageScale = Math.min(1, (width - 32) / STAGE.w, room / STAGE.h);
565
566 return (
567 <View style={[styles.screen, { backgroundColor: c.bg }]}>
568 {/* Wash and glow run edge to edge, under the status bar */}
569 <Backdrop width={width} />
570
571 <ScrollView bounces={false} showsVerticalScrollIndicator={false} contentContainerStyle={[styles.content, { paddingTop: insets.top }]}>
572 {/* Header: step indicator and skip */}
573 <Animated.View entering={FadeIn.duration(320)} style={styles.header}>
574 <View
575 role="progressbar"
576 aria-label={`Step ${STEP.current} of ${STEP.total}`}
577 aria-valuemin={1}
578 aria-valuemax={STEP.total}
579 aria-valuenow={STEP.current}
580 style={styles.steps}
581 >
582 {Array.from({ length: STEP.total }, (_, i) => {
583 const step = i + 1;
584 return (
585 <View
586 key={step}
587 style={[
588 styles.stepDot,
589 {
590 width: step === STEP.current ? 26 : 14,
591 backgroundColor: step > STEP.current ? c.stepTodo : c.accent,
592 opacity: step < STEP.current ? 0.45 : 1,
593 },
594 ]}
595 />
596 );
597 })}
598 <Text style={[styles.stepText, { color: c.muted }, TABULAR]}>
599 {STEP.current} of {STEP.total}
600 </Text>
601 </View>
602 {/* Replace with navigation to the next onboarding step. */}
603 <Pressable role="button" aria-label="Skip" hitSlop={12} style={({ pressed }) => [styles.skip, { opacity: pressed ? 0.55 : 1 }]}>
604 <Text style={[styles.quietAction, { color: c.muted }]}>Skip</Text>
605 </Pressable>
606 </Animated.View>
607
608 {/* Illustration: fills the room left above the copy, scaled down on short screens */}
609 <View onLayout={(e: LayoutChangeEvent) => setRoom(e.nativeEvent.layout.height)} style={styles.illustration}>
610 <View style={{ width: STAGE.w * stageScale, height: STAGE.h * stageScale }}>
611 <View style={[styles.stage, { transform: [{ scale: stageScale }] }]}>
612 {KINDS.map((kind, i) => (
613 <NotificationCard key={kind.key} kind={kind} index={i} on={on[kind.key]} />
614 ))}
615 <HeroBell count={waiting} ringKey={ringKey} granted={granted} />
616 </View>
617 </View>
618 </View>
619
620 {/* Copy: swaps to the success message once permission is granted */}
621 <View style={styles.copy}>
622 <Animated.View key={granted ? 'done' : 'ask'} entering={FadeInDown.duration(340)} style={styles.copyInner}>
623 <Text role="heading" aria-live="polite" style={[styles.title, { color: c.fg }]}>
624 {granted ? COPY.doneTitle : COPY.title}
625 </Text>
626 <Text style={[styles.body, { color: c.muted }]}>
627 {granted ? `You'll hear about ${listOf(picked.map((k) => k.label.toLowerCase()))}. Nothing else.` : COPY.body}
628 </Text>
629 </Animated.View>
630 </View>
631
632 {/* What you'll get */}
633 <Animated.View entering={FadeInDown.delay(140).duration(380)} style={styles.kinds}>
634 <View style={styles.kindsHead}>
635 <Text role="heading" style={[styles.kindsTitle, { color: c.muted }]}>
636 WHAT YOU'LL GET
637 </Text>
638 <Text style={[styles.kindsCount, { color: c.faint }, TABULAR]}>
639 {picked.length} of {KINDS.length} on
640 </Text>
641 </View>
642 <View style={[styles.kindsList, { backgroundColor: c.card, borderColor: c.edge }]}>
643 {KINDS.map((kind, i) => (
644 <KindRow key={kind.key} kind={kind} on={on[kind.key]} last={i === KINDS.length - 1} onToggle={() => toggle(kind.key)} />
645 ))}
646 </View>
647
648 {/* One slot: the privacy line, or the gentle hint after "Don't Allow" */}
649 <View style={styles.note}>
650 {declined ? (
651 <Animated.View
652 key="later"
653 entering={FadeInDown.duration(260)}
654 role="status"
655 aria-live="polite"
656 style={[styles.hint, { backgroundColor: c.hint }]}
657 >
658 <Settings size={14} color={c.accent} strokeWidth={2.2} />
659 <Text style={[styles.hintText, { color: c.fg }]}>{COPY.later}</Text>
660 </Animated.View>
661 ) : (
662 <Animated.View key="privacy" entering={FadeIn.duration(260)} style={styles.privacy}>
663 <Lock size={12} color={c.faint} strokeWidth={2.4} />
664 <Text style={[styles.privacyText, { color: c.muted }]}>{COPY.privacy}</Text>
665 </Animated.View>
666 )}
667 </View>
668 </Animated.View>
669 </ScrollView>
670
671 {/* Actions: opaque, above the home indicator */}
672 <Animated.View entering={FadeInDown.delay(220).duration(380)} style={[styles.actions, { paddingBottom: insets.bottom, backgroundColor: c.bg }]}>
673 <PrimaryButton state={granted ? 'done' : picked.length === 0 ? 'empty' : 'ready'} onPress={ask} />
674 {/* Replace with navigation to the next onboarding step. */}
675 <Pressable
676 role="button"
677 aria-label="Not now"
678 onPress={deny}
679 style={({ pressed }) => [styles.notNow, { opacity: pressed ? 0.55 : 1 }]}
680 >
681 <Text style={[styles.quietAction, { color: c.muted }]}>Not now</Text>
682 </Pressable>
683 </Animated.View>
684
685 <PermissionAlert open={phase === 'asking'} onAllow={allow} onDeny={deny} />
686 </View>
687 );
688}
689
690// ─── Styles ─────────────────────────────────────────────────────────────────
691
692const styles = StyleSheet.create({
693 screen: { flex: 1 },
694 content: { flexGrow: 1 },
695 fill: { flex: 1 },
696
697 // Backdrop
698 wash: { position: 'absolute', top: 0, left: 0, right: 0, height: 400 },
699 bloom: { position: 'absolute', top: -20 },
700
701 // Bell
702 bell: { position: 'absolute', left: (STAGE.w - BELL) / 2, top: 0, width: BELL, height: BELL, zIndex: 2 },
703 ripple: { borderRadius: BELL / 2, borderWidth: 2 },
704 bellGlow: { flex: 1, borderRadius: BELL / 2 },
705 bellFace: { flex: 1, borderRadius: BELL / 2, overflow: 'hidden', alignItems: 'center', justifyContent: 'center' },
706 bellSheen: { borderRadius: BELL / 2, borderTopWidth: 1, borderTopColor: tint(ON_ACCENT, 0.4) },
707 bellIcon: { transformOrigin: 'center top' },
708 tick: { position: 'absolute' },
709 badge: {
710 position: 'absolute',
711 top: -4,
712 right: -6,
713 minWidth: 22,
714 height: 22,
715 borderRadius: 11,
716 paddingHorizontal: 6,
717 alignItems: 'center',
718 justifyContent: 'center',
719 shadowColor: '#000',
720 shadowOpacity: 0.2,
721 shadowRadius: 5,
722 shadowOffset: { width: 0, height: 2 },
723 },
724 badgeText: { fontSize: 12, lineHeight: 16, fontWeight: '800' },
725
726 // Notification card
727 card: { position: 'absolute', width: CARD.w, height: CARD.h, borderRadius: 20, paddingHorizontal: 11, flexDirection: 'row', alignItems: 'center', gap: 10, borderWidth: 1 },
728 cardTile: { width: 36, height: 36, borderRadius: 10, alignItems: 'center', justifyContent: 'center' },
729 cardHead: { flexDirection: 'row', alignItems: 'baseline', gap: 8 },
730 cardTitle: { flex: 1, fontSize: 14, lineHeight: 19, fontWeight: '700', letterSpacing: -0.1 },
731 cardTime: { fontSize: 12, lineHeight: 16 },
732 cardBody: { fontSize: 13, lineHeight: 18 },
733
734 // Switch row
735 kindRow: { height: 58, paddingHorizontal: 14, flexDirection: 'row', alignItems: 'center', gap: 12 },
736 kindTile: { width: 36, height: 36, borderRadius: 11, alignItems: 'center', justifyContent: 'center' },
737 kindLabel: { fontSize: 15, lineHeight: 20, fontWeight: '600', letterSpacing: -0.1 },
738 kindDetail: { fontSize: 13, lineHeight: 18 },
739 switchTrack: { width: 48, height: 28, borderRadius: 14, padding: 2 },
740 switchThumb: { height: 24, borderRadius: 12, backgroundColor: '#fff', shadowColor: '#000', shadowOpacity: 0.22, shadowRadius: 3, shadowOffset: { width: 0, height: 1 } },
741 kindDivider: { position: 'absolute', left: 62, right: 0, bottom: 0, height: StyleSheet.hairlineWidth },
742
743 // Primary button
744 button: { height: 56, borderRadius: 18, alignItems: 'center', justifyContent: 'center', borderTopWidth: 1 },
745 buttonLabel: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8 },
746 buttonText: { fontSize: 17, fontWeight: '700', letterSpacing: -0.2 },
747
748 // System alert
749 alertLayer: { zIndex: 10, alignItems: 'center', justifyContent: 'center' },
750 alert: { width: 270, borderRadius: 14, overflow: 'hidden', shadowColor: '#000', shadowOpacity: 0.3, shadowRadius: 30, shadowOffset: { width: 0, height: 16 } },
751 alertCopy: { paddingTop: 19, paddingBottom: 18, paddingHorizontal: 16 },
752 alertTitle: { fontSize: 17, lineHeight: 22, fontWeight: '600', letterSpacing: -0.4, textAlign: 'center' },
753 alertBody: { marginTop: 4, fontSize: 13, lineHeight: 18, letterSpacing: -0.1, textAlign: 'center' },
754 alertRule: { height: StyleSheet.hairlineWidth },
755 alertActions: { height: 44, flexDirection: 'row' },
756 alertDivider: { width: StyleSheet.hairlineWidth },
757 alertAction: { flex: 1, alignItems: 'center', justifyContent: 'center' },
758 alertActionText: { fontSize: 17, lineHeight: 22 },
759 alertAllow: { fontWeight: '600' },
760
761 // Screen
762 header: { height: HEADER_H, paddingHorizontal: 24, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
763 steps: { flexDirection: 'row', alignItems: 'center', gap: 5 },
764 stepDot: { height: 5, borderRadius: 2.5 },
765 stepText: { marginLeft: 5, fontSize: 13, fontWeight: '600' },
766 skip: { paddingVertical: 8, paddingLeft: 12 },
767 quietAction: { fontSize: 15, fontWeight: '600' },
768 illustration: { flex: 1, minHeight: 170, alignItems: 'center', justifyContent: 'center' },
769 stage: { width: STAGE.w, height: STAGE.h, transformOrigin: 'left top' },
770 copy: { height: 84, marginTop: 12, paddingHorizontal: 24 },
771 copyInner: { alignItems: 'center' },
772 title: { fontSize: 28, lineHeight: 34, fontWeight: '800', letterSpacing: -0.8, textAlign: 'center' },
773 body: { marginTop: 8, maxWidth: 318, fontSize: 15, lineHeight: 21, textAlign: 'center' },
774 kinds: { marginTop: 20, paddingHorizontal: 24 },
775 kindsHead: { height: 16, marginBottom: 10, paddingHorizontal: 4, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
776 kindsTitle: { fontSize: 12, fontWeight: '700', letterSpacing: 0.9 },
777 kindsCount: { fontSize: 12, fontWeight: '600' },
778 kindsList: { borderRadius: 20, overflow: 'hidden', borderWidth: 1 },
779 note: { height: 44, alignItems: 'center', justifyContent: 'center' },
780 hint: { height: 28, paddingHorizontal: 12, borderRadius: 14, flexDirection: 'row', alignItems: 'center', gap: 6 },
781 hintText: { fontSize: 13, fontWeight: '500' },
782 privacy: { flexDirection: 'row', alignItems: 'center', gap: 6 },
783 privacyText: { fontSize: 13 },
784 actions: { paddingHorizontal: 24 },
785 notNow: { height: 44, marginTop: 2, alignItems: 'center', justifyContent: 'center' },
786});

More screens like this.

All Onboarding