Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GlassBackdrop.tsx

36 lines1.2 KB

1import { BlurView } from "expo-blur";
2import { Platform, StyleSheet, View, type ColorValue } from "react-native";
3​
4import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
5import { themeColorWithAlpha } from "../lib/mobileTheme";
6​
7/** Frosted backdrop for containers that clip their children to their shape. */
8export function GlassBackdrop(props: { readonly fallbackColor?: ColorValue }) {
9 const { themeAppearance } = useAppearancePreferences();
10 const supportsBlur = Platform.OS === "ios";
11 const colorStyle =
12 props.fallbackColor === undefined
13 ? undefined
14 : { backgroundColor: themeColorWithAlpha(String(props.fallbackColor), 1) };
15​
16 return (
17 <>
18 {supportsBlur ? (
19 <BlurView
20 pointerEvents="none"
21 intensity={80}
22 tint={themeAppearance === "dark" ? "dark" : "default"}
23 style={StyleSheet.absoluteFill}
24 />
25 ) : null}
26 <View
27 pointerEvents="none"
28 className="absolute inset-0 bg-card"
29 style={[
30 colorStyle,
31 { opacity: supportsBlur ? (themeAppearance === "dark" ? 0.25 : 0.55) : 1 },
32 ]}
33 />
34 </>
35 );