The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useNavigation, useRoute } from "@react-navigation/native"; |
| 2 | import { use, type ComponentProps } from "react"; |
| 3 | import { Platform } from "react-native"; |
| 4 | |
| 5 | import { ListRow } from "../../../components/ui/ListRow"; |
| 6 | import { ListRowLayout } from "../../../components/ui/ListRowLayout"; |
| 7 | import { RowPressable } from "../../../components/ui/RowPressable"; |
| 8 | import { cn } from "../../../lib/cn"; |
| 9 | import type { SettingsLegalDocumentTarget, SettingsPageTarget } from "./settings-page-targets"; |
| 10 | import { SettingsSidebarContext } from "./SettingsSection"; |
| 11 | import { openSettings } from "../settings-navigation"; |
| 12 | |
| 13 | export function SettingsRow(props: { |
| 14 | readonly disabled?: boolean; |
| 15 | readonly icon: ComponentProps<typeof ListRow>["icon"]; |
| 16 | readonly label: string; |
| 17 | readonly value?: string; |
| 18 | readonly valuePosition?: "below" | "trailing"; |
| 19 | readonly target?: SettingsPageTarget; |
| 20 | readonly fullScreenTarget?: SettingsLegalDocumentTarget; |
| 21 | readonly onPress?: () => void; |
| 22 | }) { |
| 23 | const navigation = useNavigation(); |
| 24 | const sidebar = use(SettingsSidebarContext); |
| 25 | // The Settings list opens pages in place of the detail column; a page's own rows push below. |
| 26 | const inList = ["Home", "Settings"].includes(useRoute().name); |
| 27 | const valueBelow = |
| 28 | props.valuePosition === "below" || |
| 29 | (props.valuePosition === undefined && Platform.OS === "android"); |
| 30 | const content = { |
| 31 | icon: props.icon, |
| 32 | label: props.label, |
| 33 | description: valueBelow ? props.value : undefined, |
| 34 | detail: valueBelow ? undefined : props.value, |
| 35 | disabled: props.disabled, |
| 36 | }; |
| 37 | const onPress = () => { |
| 38 | if (props.target) { |
| 39 | if (inList) openSettings(navigation, props.target); |
| 40 | else navigation.navigate(props.target); |
| 41 | } else if (props.fullScreenTarget) { |
| 42 | navigation.navigate(props.fullScreenTarget); |
| 43 | } else { |
| 44 | props.onPress?.(); |
| 45 | } |
| 46 | }; |
| 47 | if (sidebar) { |
| 48 | const selected = props.target !== undefined && props.target === sidebar.selected; |
| 49 | return ( |
| 50 | <RowPressable |
| 51 | accessibilityRole="button" |
| 52 | accessibilityLabel={[props.label, props.value].filter(Boolean).join(", ")} |
| 53 | accessibilityState={{ disabled: Boolean(props.disabled), selected }} |
| 54 | disabled={props.disabled} |
| 55 | onPress={onPress} |
| 56 | className={cn("rounded-2xl", selected && "bg-thread-selected")} |
| 57 | > |
| 58 | <ListRowLayout {...content} /> |
| 59 | </RowPressable> |
| 60 | ); |
| 61 | } |
| 62 | return <ListRow {...content} onPress={onPress} />; |
| 63 | } |