Open History to see the last commit
1import { MaterialListRow } from "../../../components/MaterialListRow";
2import { useNavigation } from "@react-navigation/native";
3import type { ComponentProps } from "react";
4import { Platform, Pressable, View } from "react-native";
5
6import { SymbolView } from "../../../components/AppSymbol";
7import { AppText as Text } from "../../../components/AppText";
8import type { SettingsLegalDocumentTarget, SettingsSheetTarget } from "./settings-sheet-targets";
9import { cn } from "../../../lib/cn";
10
11type SymbolName = ComponentProps<typeof SymbolView>["name"];
12
13export function SettingsRow(props: {
14 readonly disabled?: boolean;
15 readonly icon: SymbolName;
16 readonly label: string;
17 readonly value?: string;
18 readonly valuePosition?: "below" | "trailing";
19 readonly target?: SettingsSheetTarget;
20 readonly fullScreenTarget?: SettingsLegalDocumentTarget;
21 readonly onPress?: () => void;
22}) {
23 const navigation = useNavigation();
24 if (Platform.OS === "android") {
25 return (
26 <MaterialListRow
27 className="bg-grouped-card"
28 title={props.label}
29 subtitle={props.valuePosition === "trailing" ? undefined : props.value}
30 accessibilityLabel={[props.label, props.value].filter(Boolean).join(", ")}
31 trailing={
32 props.valuePosition === "trailing" && props.value ? (
33 <View className="flex-row items-center gap-3">
34 <Text className="text-sm text-foreground-muted">{props.value}</Text>
35 <SymbolView name="chevron.right" size={16} tintColorClassName="accent-chevron" />
36 </View>
37 ) : undefined
38 }
39 disabled={props.disabled}
40 leading={
41 <SymbolView
42 name={props.icon}
43 size={24}
44 tintColorClassName="accent-icon"
45 type="monochrome"
46 weight="regular"
47 />
48 }
49 onPress={() => {
50 if (props.target)
51 navigation.navigate("SettingsSheet", {
52 screen: "SettingsContent",
53 params: { screen: props.target },
54 });
55 else if (props.fullScreenTarget) navigation.navigate(props.fullScreenTarget);
56 else props.onPress?.();
57 }}
58 />
59 );
60 }
61 const content = (
62 <View className={cn("flex-row items-center gap-4 p-4", props.disabled && "opacity-[0.45]")}>
63 <SymbolView
64 name={props.icon}
65 size={22}
66 tintColorClassName="accent-icon"
67 type="monochrome"
68 weight="regular"
69 />
70 <>
71 <Text className="shrink-0 text-lg text-foreground" numberOfLines={1}>
72 {props.label}
73 </Text>
74 <View className="min-w-0 flex-1 items-end">
75 {props.value ? (
76 <Text
77 className="max-w-[180px] text-right text-base text-foreground-muted"
78 ellipsizeMode="middle"
79 numberOfLines={1}
80 >
81 {props.value}
82 </Text>
83 ) : null}
84 </View>
85 </>
86 <SymbolView
87 name="chevron.right"
88 size={16}
89 tintColorClassName="accent-chevron"
90 type="monochrome"
91 weight="semibold"
92 />
93 </View>
94 );
95
96 const target = props.target;
97 if (target) {
98 return (
99 <Pressable
100 accessibilityLabel={props.label}
101 accessibilityRole="button"
102 disabled={props.disabled}
103 onPress={() =>
104 navigation.navigate("SettingsSheet", {
105 screen: "SettingsContent",
106 params: { screen: target },
107 })
108 }
109 >
110 {content}
111 </Pressable>
112 );
113 }
114
115 const fullScreenTarget = props.fullScreenTarget;
116 if (fullScreenTarget) {
117 return (
118 <Pressable
119 accessibilityLabel={props.label}
120 accessibilityRole="button"
121 disabled={props.disabled}
122 onPress={() => navigation.navigate(fullScreenTarget)}
123 >
124 {content}
125 </Pressable>
126 );
127 }
128
129 return (
130 <Pressable
131 accessibilityLabel={props.label}
132 accessibilityRole="button"
133 disabled={props.disabled}
134 onPress={props.onPress}
135 >
136 {content}
137 </Pressable>
138 );
139}