refactor(mobile): share themed choice rows in settings (#18516)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-10-11 22:31:14 -07:00
1 parent 9a2b9a2d40
commit abc80c80a7
3 files changed
+64 -43

No files matched your search

@@ -0,0 +1,60 @@
import { Platform, View } from "react-native";
import { useResolveClassNames } from "uniwind";
import { cn } from "../lib/cn";
import { SymbolView } from "./AppSymbol";
import { ListRowLayout } from "./ListRowLayout";
import { MaterialRadioIndicator } from "./MaterialRadioIndicator";
import { RowPressable } from "./RowPressable";
export function ListChoiceRow(props: {
readonly label: string;
readonly description?: string;
readonly selected: boolean;
readonly separated?: boolean;
readonly disabled?: boolean;
readonly onPress: () => void;
}) {
const rippleStyle = useResolveClassNames("bg-subtle-strong");
return (
<RowPressable
accessibilityRole="radio"
accessibilityLabel={props.label}
accessibilityHint={props.description}
accessibilityState={{ checked: props.selected, disabled: Boolean(props.disabled) }}
disabled={props.disabled}
onPress={props.onPress}
android_ripple={{ color: rippleStyle.backgroundColor }}
unstable_pressDelay={Platform.OS === "android" ? 50 : undefined}
className={cn(
props.selected ? "bg-subtle" : "bg-grouped-card",
props.separated && "border-t border-border-subtle",
)}
>
<ListRowLayout
label={props.label}
description={props.description}
disabled={props.disabled}
accessory={
<View
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"
className="size-6 items-center justify-center"
>
{Platform.OS === "android" ? (
<MaterialRadioIndicator selected={props.selected} />
) : props.selected ? (
<SymbolView
name="checkmark"
size={18}
tintColorClassName="accent-primary-text"
type="monochrome"
weight="semibold"
/>
) : null}
</View>
}
/>
</RowPressable>
);
}
@@ -22,7 +22,8 @@ export function MaterialRadioIndicator({ selected }: { readonly selected: boolea
height: 20,
borderRadius: 10,
borderWidth: 2,
borderColor: themeVariables[selected ? "--color-primary" : "--color-foreground-muted"],
borderColor:
themeVariables[selected ? "--color-primary-text" : "--color-foreground-muted"],
alignItems: "center",
justifyContent: "center",
}}
@@ -33,7 +34,7 @@ export function MaterialRadioIndicator({ selected }: { readonly selected: boolea
width: 10,
height: 10,
borderRadius: 5,
backgroundColor: themeVariables["--color-primary"],
backgroundColor: themeVariables["--color-primary-text"],
}}
/>
) : null}
@@ -1,41 +1 @@
import { Pressable, View } from "react-native";
import { AppText as Text } from "../../../components/AppText";
import { SymbolView } from "../../../components/AppSymbol";
export function SettingsChoiceRow(props: {
readonly label: string;
readonly description: string;
readonly selected: boolean;
readonly separated: boolean;
readonly disabled: boolean;
readonly onPress: () => void;
}) {
return (
<Pressable
accessibilityRole="radio"
accessibilityState={{ checked: props.selected, disabled: props.disabled }}
className={
props.separated
? "flex-row items-center gap-4 border-t border-border-subtle p-4 active:opacity-70"
: "flex-row items-center gap-4 p-4 active:opacity-70"
}
disabled={props.disabled}
onPress={props.onPress}
>
<View className="min-w-0 flex-1 gap-1">
<Text className="text-lg text-foreground android:text-base">{props.label}</Text>
<Text className="text-sm leading-normal text-foreground-muted">{props.description}</Text>
</View>
{props.selected ? (
<SymbolView
name="checkmark"
size={18}
tintColorClassName="accent-icon"
type="monochrome"
weight="semibold"
/>
) : null}
</Pressable>
);
}
export { ListChoiceRow as SettingsChoiceRow } from "../../../components/ListChoiceRow";