Skip to content

Instantly share code, notes, and snippets.

@fav-devs
Created May 22, 2026 18:45
Show Gist options
  • Select an option

  • Save fav-devs/462aa858981fc7a4991e3bfceb0f4cc3 to your computer and use it in GitHub Desktop.

Select an option

Save fav-devs/462aa858981fc7a4991e3bfceb0f4cc3 to your computer and use it in GitHub Desktop.
Reusable Permission Screen
/**
* PermissionScreen — drop-in iOS permission onboarding screen
*
* Dependencies (all standard Expo SDK packages):
* expo-blur, expo-linear-gradient, react-native-svg,
* react-native-safe-area-context, react-native-reanimated
*
* Usage:
* <PermissionScreen
* appName="MyApp"
* icon={<Image source={require("./icon.png")} style={{ width: 40, height: 40, borderRadius: 10 }} />}
* permissionTitle="Send You Notifications"
* permissionMessage="We'll let you know about activity and reminders."
* title="Stay in the loop"
* description="Get notified about the things that matter to you."
* primaryLabel="Enable Notifications"
* onPrimary={async () => { await Notifications.requestPermissionsAsync(); }}
* onSkip={() => router.replace("/")}
* />
*/
import type { ReactNode } from "react";
import { useState } from "react";
import {
Pressable,
StyleSheet,
Text,
View,
useWindowDimensions,
} from "react-native";
import { LinearGradient } from "expo-linear-gradient";
import { BlurView } from "expo-blur";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import Svg, { Path, Rect } from "react-native-svg";
// ─── iPhone SVG constants (iPhone 16 Pro proportions) ────────────────────────
const SVG_W = 823;
const SVG_H = 1677;
const BODY_X = 38;
const BODY_Y = 32;
const BODY_W = 746;
const BODY_H = 1618;
const DI_X = 291;
const DI_Y = 54;
const DI_W = 238;
const DI_H = 69;
const BODY_PATH =
"M50.0983 92.6071C38 116.351 38 147.434 38 209.6L38 1472.4C38 1534.57 38 1565.65 50.0983 1589.39" +
"C60.7402 1610.28 77.7211 1627.26 98.6071 1637.9C122.351 1650 153.434 1650 215.6 1650H606.4" +
"C668.566 1650 699.649 1650 723.393 1637.9C744.279 1627.26 761.26 1610.28 771.902 1589.39" +
"C784 1565.65 784 1534.57 784 1472.4V209.6C784 147.434 784 116.351 771.902 92.6071" +
"C761.26 71.7211 744.279 54.7402 723.393 44.0983C699.649 32 668.566 32 606.4 32L215.6 32" +
"C153.434 32 122.351 32 98.6071 44.0983C77.7211 54.7402 60.7402 71.7211 50.0983 92.6071Z";
// ─── Types ────────────────────────────────────────────────────────────────────
export type PermissionScreenProps = {
/** App name shown in the iOS-style alert header */
appName?: string;
/** Icon rendered inside the alert — pass an <Image>, <Text> emoji, or any node */
icon?: ReactNode;
/** Permission dialog title, e.g. "Send You Notifications" */
permissionTitle: string;
/** Permission dialog body text */
permissionMessage: string;
/** Bold heading at the bottom of the screen */
title: string;
/** Supporting copy below the heading */
description: string;
/** Primary CTA label — defaults to "Continue" */
primaryLabel?: string;
/** Called (awaited) when the user taps the primary button */
onPrimary: () => void | Promise<void>;
/** Renders a "Maybe Later" link below the CTA when provided */
onSkip?: () => void;
};
// ─── Helpers ──────────────────────────────────────────────────────────────────
function IPhoneFrame({ width, height }: { width: number; height: number }) {
return (
<Svg
width={width}
height={height}
viewBox={`0 0 ${SVG_W} ${SVG_H}`}
style={StyleSheet.absoluteFill}
pointerEvents="none"
>
<Path d={BODY_PATH} fill="none" stroke="#333344" strokeWidth={12} />
{/* Dynamic island */}
<Rect x={DI_X} y={DI_Y} width={DI_W} height={DI_H} rx={DI_H / 2} fill="#111111" />
<Rect
x={DI_X + DI_W - DI_H + 8}
y={DI_Y + 17}
width={DI_H - 34}
height={DI_H - 34}
rx={(DI_H - 34) / 2}
fill="#1a1a1a"
fillOpacity={0.8}
/>
{/* Home indicator */}
<Rect x={311} y={1624} width={200} height={7} rx={4} fill="#ffffff" fillOpacity={0.12} />
</Svg>
);
}
function SkeletonBar({
width,
height = 10,
opacity = 1,
radius = 6,
}: {
width: number | `${number}%`;
height?: number;
opacity?: number;
radius?: number;
}) {
return (
<View
style={{
width,
height,
borderRadius: radius,
backgroundColor: `rgba(255,255,255,${0.07 * opacity})`,
}}
/>
);
}
function SkeletonContent({ bodyWidth, bodyHeight }: { bodyWidth: number; bodyHeight: number }) {
const p = bodyWidth * 0.08;
return (
<View style={{ flex: 1 }}>
<View
style={{
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
paddingHorizontal: p,
paddingTop: bodyHeight * 0.04,
paddingBottom: bodyHeight * 0.015,
}}
>
<SkeletonBar width={bodyWidth * 0.18} height={7} opacity={0.8} radius={4} />
<View style={{ flexDirection: "row", gap: bodyWidth * 0.03 }}>
<SkeletonBar width={bodyWidth * 0.07} height={7} opacity={0.6} radius={4} />
<SkeletonBar width={bodyWidth * 0.07} height={7} opacity={0.6} radius={4} />
<SkeletonBar width={bodyWidth * 0.1} height={7} opacity={0.6} radius={4} />
</View>
</View>
<View style={{ paddingHorizontal: p, gap: bodyHeight * 0.012, marginTop: bodyHeight * 0.025 }}>
<SkeletonBar width={bodyWidth * 0.55} height={13} opacity={1.2} radius={7} />
<SkeletonBar width={bodyWidth * 0.38} height={9} opacity={0.7} radius={5} />
</View>
<View
style={{
marginHorizontal: p,
marginTop: bodyHeight * 0.035,
padding: bodyWidth * 0.07,
borderRadius: bodyWidth * 0.07,
backgroundColor: "rgba(255,255,255,0.04)",
gap: bodyHeight * 0.014,
}}
>
<SkeletonBar width={bodyWidth * 0.45} height={10} radius={5} />
<SkeletonBar width={bodyWidth * 0.68} height={8} opacity={0.7} radius={4} />
<SkeletonBar width={bodyWidth * 0.55} height={8} opacity={0.7} radius={4} />
</View>
<View style={{ paddingHorizontal: p, marginTop: bodyHeight * 0.03, gap: bodyHeight * 0.022 }}>
{[0.82, 0.65, 0.75, 0.58, 0.72, 0.68].map((w, i) => (
<View key={i} style={{ flexDirection: "row", alignItems: "center", gap: bodyWidth * 0.04 }}>
<View
style={{
width: bodyWidth * 0.1,
height: bodyWidth * 0.1,
borderRadius: bodyWidth * 0.03,
backgroundColor: "rgba(255,255,255,0.06)",
}}
/>
<View style={{ gap: bodyHeight * 0.008, flex: 1 }}>
<SkeletonBar width={`${w * 100}%`} height={8} opacity={0.9} radius={4} />
<SkeletonBar width={`${w * 65}%`} height={6} opacity={0.5} radius={3} />
</View>
</View>
))}
</View>
</View>
);
}
function DefaultIcon({ size }: { size: number }) {
return (
<View
style={{
width: size,
height: size,
borderRadius: size * 0.22,
backgroundColor: "rgba(120,120,255,0.18)",
alignItems: "center",
justifyContent: "center",
}}
>
<Text style={{ fontSize: size * 0.52 }}>🔔</Text>
</View>
);
}
function PermissionAlert({
appName,
title,
message,
icon,
bodyWidth,
}: {
appName: string;
title: string;
message: string;
icon: ReactNode;
bodyWidth: number;
}) {
const fs = bodyWidth * 0.068;
return (
<BlurView
tint="light"
intensity={96}
style={{
borderRadius: bodyWidth * 0.09,
overflow: "hidden",
marginHorizontal: bodyWidth * 0.055,
}}
>
<View style={{ padding: bodyWidth * 0.07, gap: bodyWidth * 0.028, alignItems: "center" }}>
{icon}
<Text style={{ fontSize: fs * 0.7, fontWeight: "500", color: "rgba(28,28,30,0.55)", textAlign: "center" }}>
{`"${appName}"`} Would Like to
</Text>
<Text
style={{
fontSize: fs * 0.86,
fontWeight: "700",
color: "#1C1C1E",
textAlign: "center",
lineHeight: fs * 1.15,
marginTop: -bodyWidth * 0.01,
}}
>
{title}
</Text>
<Text
style={{ fontSize: fs * 0.64, color: "rgba(60,60,67,0.85)", textAlign: "center", lineHeight: fs * 0.92 }}
>
{message}
</Text>
</View>
</BlurView>
);
}
function PhoneMockup({
appName,
icon,
permissionTitle,
permissionMessage,
phoneHeight,
}: {
appName: string;
icon: ReactNode;
permissionTitle: string;
permissionMessage: string;
phoneHeight: number;
}) {
const phoneWidth = phoneHeight * (SVG_W / SVG_H);
const bodyLeft = phoneWidth * (BODY_X / SVG_W);
const bodyTop = phoneHeight * (BODY_Y / SVG_H);
const bodyWidth = phoneWidth * (BODY_W / SVG_W);
const bodyHeight = phoneHeight * (BODY_H / SVG_H);
const bodyRadius = bodyWidth * 0.153;
return (
<View style={{ width: phoneWidth, height: phoneHeight }}>
<View
style={{
position: "absolute",
left: bodyLeft,
top: bodyTop,
width: bodyWidth,
height: bodyHeight,
borderRadius: bodyRadius,
overflow: "hidden",
backgroundColor: "#0A0A14",
}}
>
<SkeletonContent bodyWidth={bodyWidth} bodyHeight={bodyHeight} />
<LinearGradient
colors={["rgba(0,0,0,0)", "rgba(0,0,0,0.5)", "rgba(0,0,0,0.72)"]}
locations={[0.25, 0.6, 1]}
style={StyleSheet.absoluteFill}
pointerEvents="none"
/>
<View style={{ position: "absolute", bottom: bodyHeight * 0.42, left: 0, right: 0 }}>
<PermissionAlert
appName={appName}
title={permissionTitle}
message={permissionMessage}
icon={icon}
bodyWidth={bodyWidth}
/>
</View>
</View>
<IPhoneFrame width={phoneWidth} height={phoneHeight} />
</View>
);
}
// ─── Screen ───────────────────────────────────────────────────────────────────
export function PermissionScreen({
appName = "MyApp",
icon,
permissionTitle,
permissionMessage,
title,
description,
primaryLabel = "Continue",
onPrimary,
onSkip,
}: PermissionScreenProps) {
const { height } = useWindowDimensions();
const insets = useSafeAreaInsets();
const [loading, setLoading] = useState(false);
const phoneHeight = height * 0.82;
const resolvedIcon = icon ?? <DefaultIcon size={phoneHeight * (BODY_W / SVG_W) * 0.15} />;
const handlePrimary = async () => {
setLoading(true);
try {
await Promise.resolve(onPrimary());
} finally {
setLoading(false);
}
};
return (
<View style={styles.root}>
<LinearGradient
colors={["#0F0A1E", "#0A0A14", "#060608"]}
locations={[0, 0.5, 1]}
style={StyleSheet.absoluteFill}
/>
<View
style={{ position: "absolute", top: insets.top + 8, left: 0, right: 0, alignItems: "center" }}
pointerEvents="none"
>
<PhoneMockup
appName={appName}
icon={resolvedIcon}
permissionTitle={permissionTitle}
permissionMessage={permissionMessage}
phoneHeight={phoneHeight}
/>
</View>
<View style={[styles.overlay, { paddingBottom: insets.bottom + 24 }]}>
<LinearGradient
colors={["rgba(6,6,8,0)", "rgba(6,6,8,0.88)", "rgba(6,6,8,1)"]}
locations={[0, 0.28, 0.58]}
style={StyleSheet.absoluteFill}
pointerEvents="none"
/>
<View style={styles.textBlock}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.description}>{description}</Text>
</View>
<Pressable
onPress={() => { void handlePrimary(); }}
disabled={loading}
style={({ pressed }) => [styles.primaryBtn, { opacity: pressed || loading ? 0.75 : 1 }]}
>
<Text style={styles.primaryLabel}>{loading ? "…" : primaryLabel}</Text>
</Pressable>
{onSkip ? (
<Pressable onPress={onSkip} hitSlop={12}>
<Text style={styles.skipLabel}>Maybe Later</Text>
</Pressable>
) : null}
</View>
</View>
);
}
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: "#060608",
},
overlay: {
position: "absolute",
bottom: 0,
left: 0,
right: 0,
paddingHorizontal: 28,
paddingTop: 80,
gap: 16,
alignItems: "center",
},
textBlock: {
gap: 8,
alignItems: "center",
},
title: {
fontSize: 28,
fontWeight: "800",
color: "#FFFFFF",
textAlign: "center",
letterSpacing: -0.5,
lineHeight: 34,
},
description: {
fontSize: 15,
color: "rgba(255,255,255,0.45)",
textAlign: "center",
lineHeight: 22,
},
primaryBtn: {
width: "100%",
paddingVertical: 16,
borderRadius: 999,
alignItems: "center",
justifyContent: "center",
backgroundColor: "rgba(255,255,255,0.14)",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "rgba(255,255,255,0.2)",
},
primaryLabel: {
fontSize: 17,
fontWeight: "700",
color: "#FFFFFF",
letterSpacing: 0.2,
},
skipLabel: {
fontSize: 15,
color: "rgba(255,255,255,0.3)",
fontWeight: "500",
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment