Open History to see the last commit
1import { Platform, Pressable, Switch, View, type SwitchProps } from "react-native";
2
3import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
4import { SymbolView } from "./AppSymbol";
5
6export function ThemedSwitch(props: SwitchProps) {
7 const { materialYouStyleLayoutActive } = useAppearancePreferences();
8 if (materialYouStyleLayoutActive) {
9 return (
10 <Pressable
11 accessibilityHint={props.accessibilityHint}
12 accessibilityLabel={props.accessibilityLabel}
13 accessibilityRole="switch"
14 accessibilityState={{ checked: Boolean(props.value), disabled: props.disabled }}
15 disabled={props.disabled}
16 hitSlop={8}
17 onPress={() => props.onValueChange?.(!props.value)}
18 style={props.style}
19 testID={props.testID}
20 className={props.disabled ? "opacity-40" : "active:opacity-70"}
21 >
22 <View
23 className={
24 props.value
25 ? "h-8 w-[52px] items-end justify-center rounded-full border-2 border-switch-active-track bg-switch-active-track px-0.5"
26 : "h-8 w-[52px] items-start justify-center rounded-full border-2 border-switch-inactive-thumb bg-switch-inactive-track px-0.5"
27 }
28 >
29 <View
30 className={
31 props.value
32 ? "size-6 items-center justify-center rounded-full bg-switch-active-thumb"
33 : "size-6 items-center justify-center rounded-full bg-switch-inactive-thumb"
34 }
35 >
36 <SymbolView
37 name={props.value ? "checkmark" : "xmark"}
38 size={13}
39 tintColorClassName={
40 props.value ? "accent-switch-active-track" : "accent-switch-inactive-track"
41 }
42 type="monochrome"
43 />
44 </View>
45 </View>
46 </Pressable>
47 );
48 }
49
50 return (
51 <Switch
52 {...props}
53 ios_backgroundColorClassName="accent-switch-inactive-track"
54 thumbColorClassName={
55 Platform.OS === "android"
56 ? props.value
57 ? "accent-switch-active-thumb"
58 : "accent-switch-inactive-thumb"
59 : undefined
60 }
61 trackColorOffClassName="accent-switch-inactive-track"
62 trackColorOnClassName="accent-switch-active-track"
63 />
64 );
65}