Skip to content
TypeScript

refactor(mobile): split settings selection rows by platform (#12384)

Julius Marminge7230f6b1be4d
diff --git a/apps/mobile/src/features/threads/ThreadSettingsRows.android.tsx b/apps/mobile/src/features/threads/ThreadSettingsRows.android.tsx
new file mode 100644
index 00000000000..98b414ef55d
--- /dev/null
+++ b/apps/mobile/src/features/threads/ThreadSettingsRows.android.tsx
@@ -0,0 +1,29 @@
+import { MaterialRadioIndicator } from "../../components/MaterialRadioIndicator";
+import {
+ ModelRowContent,
+ ChoiceRowContent,
+ type ModelRowProps,
+ type ChoiceRowProps,
+} from "./ThreadSettingsRows.shared";
+
+export function ModelRow(props: ModelRowProps) {
+ return (
+ <ModelRowContent
+ {...props}
+ labelNumberOfLines={2}
+ minimumHeight={56}
+ selectedClassName={props.selected ? "bg-thread-selected" : undefined}
+ leadingSelection={<MaterialRadioIndicator selected={props.selected} />}
+ />
+ );
+}
+
+export function ChoiceRow(props: ChoiceRowProps) {
+ return (
+ <ChoiceRowContent
+ {...props}
+ minimumHeight={56}
+ leadingSelection={<MaterialRadioIndicator selected={props.selected} />}
+ />
+ );
+}
diff --git a/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx b/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx
new file mode 100644
index 00000000000..70a66704cdd
--- /dev/null
+++ b/apps/mobile/src/features/threads/ThreadSettingsRows.shared.tsx
@@ -0,0 +1,140 @@
+import type { ReactNode } from "react";
+import { Pressable, View } from "react-native";
+import { AppText as Text } from "../../components/AppText";
+import { SymbolView } from "../../components/AppSymbol";
+import { cn } from "../../lib/cn";
+import type { ModelOption } from "../../lib/modelOptions";
+
+export type ModelRowProps = {
+ readonly option: ModelOption;
+ readonly selected: boolean;
+ readonly onPress: () => void;
+ readonly isFavorite: boolean;
+ readonly favoritesLoaded: boolean;
+ readonly onToggleFavorite: () => void;
+ readonly isFirst: boolean;
+ readonly isLast: boolean;
+};
+
+export type ChoiceRowProps = {
+ readonly label: string;
+ readonly description?: string;
+ readonly selected: boolean;
+ readonly onPress: () => void;
+ readonly isLast: boolean;
+};
+
+type RowSelectionProps = {
+ readonly leadingSelection?: ReactNode;
+ readonly trailingSelection?: ReactNode;
+ readonly minimumHeight?: number;
+};
+
+export function ModelRowContent(
+ props: ModelRowProps &
+ RowSelectionProps & {
+ readonly labelNumberOfLines: number;
+ readonly selectedClassName?: string;
+ },
+) {
+ return (
+ <View
+ style={props.minimumHeight === undefined ? undefined : { minHeight: props.minimumHeight }}
+ className={cn(
+ "mx-4 min-h-11 flex-row items-center gap-2 bg-card px-4",
+ props.selectedClassName,
+ props.isFirst && "rounded-t-2xl",
+ props.isLast ? "rounded-b-2xl" : "border-b border-border-subtle",
+ )}
+ >
+ <Pressable
+ accessibilityLabel={[props.option.label, props.option.subtitle].filter(Boolean).join(", ")}
+ accessibilityRole="radio"
+ accessibilityState={{
+ checked: props.selected,
+ disabled: props.option.isUnavailable === true,
+ }}
+ className="min-h-11 min-w-0 flex-1 flex-row items-center gap-2 active:opacity-70"
+ disabled={props.option.isUnavailable}
+ onPress={props.onPress}
+ >
+ {props.leadingSelection}
+ <View className="min-w-0 flex-1">
+ <View className="flex-row items-center gap-2">
+ <Text
+ className="min-w-0 shrink text-base font-t3-medium text-foreground"
+ numberOfLines={props.labelNumberOfLines}
+ >
+ {props.option.label}
+ </Text>
+ {props.option.isDefault ? (
+ <View className="rounded-md bg-subtle-strong px-1.5 py-0.5">
+ <Text className="text-3xs font-t3-bold text-foreground-muted">Default</Text>
+ </View>
+ ) : null}
+ {props.option.isLegacy ? (
+ <View className="rounded-md bg-subtle px-1.5 py-0.5">
+ <Text className="text-3xs font-t3-bold text-foreground-muted">Legacy</Text>
+ </View>
+ ) : null}
+ {props.option.isUnavailable ? (
+ <Text className="text-xs text-foreground">Unavailable</Text>
+ ) : null}
+ </View>
+ {props.option.subtitle ? (
+ <Text
+ className="text-xs text-foreground-muted"
+ numberOfLines={props.labelNumberOfLines}
+ >
+ {props.option.subtitle}
+ </Text>
+ ) : null}
+ </View>
+ {props.trailingSelection}
+ </Pressable>
+ <Pressable
+ accessibilityLabel={`${props.isFavorite ? "Remove from" : "Add to"} favorites: ${
+ props.option.providerLabel
+ }, ${props.option.label}`}
+ accessibilityRole="button"
+ accessibilityState={{ disabled: !props.favoritesLoaded, selected: props.isFavorite }}
+ className="min-h-11 min-w-11 items-center justify-center"
+ disabled={!props.favoritesLoaded}
+ onPress={props.onToggleFavorite}
+ >
+ <SymbolView
+ name={props.isFavorite ? "star.fill" : "star"}
+ size={18}
+ tintColorClassName={props.isFavorite ? "accent-icon" : "accent-icon-subtle"}
+ type="monochrome"
+ />
+ </Pressable>
+ </View>
+ );
+}
+
+/** Single option inside a submenu panel. */
+export function ChoiceRowContent(props: ChoiceRowProps & RowSelectionProps) {
+ return (
+ <Pressable
+ accessibilityLabel={props.description ? `${props.label}. ${props.description}` : props.label}
+ accessibilityRole="radio"
+ accessibilityState={{ checked: props.selected }}
+ onPress={props.onPress}
+ style={props.minimumHeight === undefined ? undefined : { minHeight: props.minimumHeight }}
+ className={cn(
+ "min-h-14 flex-row items-center gap-3 bg-card px-4 py-3 active:bg-subtle",
+ !props.isLast && "border-b border-border-subtle",
+ )}
+ >
+ {props.leadingSelection}
+ <View className="min-w-0 flex-1 gap-0.5">
+ <Text className="text-base font-t3-medium text-foreground">{props.label}</Text>
+ {props.description ? (
+ <Text className="text-sm leading-5 text-foreground-muted">{props.description}</Text>
+ ) : null}
+ </View>
+ {props.trailingSelection}
+ </Pressable>
+ );
+}
diff --git a/apps/mobile/src/features/threads/ThreadSettingsRows.tsx b/apps/mobile/src/features/threads/ThreadSettingsRows.tsx
new file mode 100644
index 00000000000..016be4cb9c1
--- /dev/null
+++ b/apps/mobile/src/features/threads/ThreadSettingsRows.tsx
@@ -0,0 +1,38 @@
+import { SymbolView } from "../../components/AppSymbol";
+import {
+ ModelRowContent,
+ ChoiceRowContent,
+ type ModelRowProps,
+ type ChoiceRowProps,
+} from "./ThreadSettingsRows.shared";
+
+function SelectedCheckmark(props: { readonly selected: boolean }) {
+ return props.selected ? (
+ <SymbolView
+ name="checkmark"
+ size={16}
+ tintColorClassName="accent-icon"
+ type="monochrome"
+ weight="semibold"
+ />
+ ) : null;
+}
+
+export function ModelRow(props: ModelRowProps) {
+ return (
+ <ModelRowContent
+ {...props}
+ labelNumberOfLines={1}
+ trailingSelection={<SelectedCheckmark selected={props.selected} />}
+ />
+ );
+}
+
+export function ChoiceRow(props: ChoiceRowProps) {
+ return (
+ <ChoiceRowContent
+ {...props}
+ trailingSelection={<SelectedCheckmark selected={props.selected} />}
+ />
+ );
+}
diff --git a/apps/mobile/src/features/threads/ThreadSettingsSheet.tsx b/apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
index 6c0218d453f..9dbefe6018b 100644
--- a/apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
@@ -40,7 +40,6 @@ import { AppText as Text } from "../../components/AppText";
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
import { MaterialButton } from "../../components/MaterialButton";
import { MaterialIconButton } from "../../components/MaterialIconButton";
-import { MaterialRadioIndicator } from "../../components/MaterialRadioIndicator";
import { ProviderIcon } from "../../components/ProviderIcon";
import { ThemedSwitch } from "../../components/ThemedSwitch";
import { cn } from "../../lib/cn";
@@ -69,6 +68,7 @@ import {
NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET,
NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED,
} from "../layout/native-mail-search-toolbar";
+import { ModelRow, ChoiceRow } from "./ThreadSettingsRows";
import { RUNTIME_MODE_CHOICES, selectableChoices } from "./thread-settings-options";
import {
canCommitPendingModel,
@@ -113,101 +113,6 @@ const EMPTY_MODEL_FAVORITES: ReadonlyArray<{
readonly model: string;
}> = [];
const FAVORITES_PROVIDER_FILTER = "@favorites";
-function ModelRow(props: {
- readonly option: ModelOption;
- readonly selected: boolean;
- readonly onPress: () => void;
- readonly isFavorite: boolean;
- readonly favoritesLoaded: boolean;
- readonly onToggleFavorite: () => void;
- readonly isFirst: boolean;
- readonly isLast: boolean;
-}) {
- const selectedMaterialRow = Platform.OS === "android" && props.selected;
- return (
- <View
- style={Platform.OS === "android" ? { minHeight: 56 } : undefined}
- className={cn(
- "mx-4 min-h-11 flex-row items-center gap-2 bg-card px-4",
- selectedMaterialRow && "bg-thread-selected",
- props.isFirst && "rounded-t-2xl",
- props.isLast ? "rounded-b-2xl" : "border-b border-border-subtle",
- )}
- >
- <Pressable
- accessibilityLabel={[props.option.label, props.option.subtitle].filter(Boolean).join(", ")}
- accessibilityRole="radio"
- accessibilityState={{
- checked: props.selected,
- disabled: props.option.isUnavailable === true,
- }}
- className="min-h-11 min-w-0 flex-1 flex-row items-center gap-2 active:opacity-70"
- disabled={props.option.isUnavailable}
- onPress={props.onPress}
- >
- {Platform.OS === "android" ? <MaterialRadioIndicator selected={props.selected} /> : null}
- <View className="min-w-0 flex-1">
- <View className="flex-row items-center gap-2">
- <Text
- className="min-w-0 shrink text-base font-t3-medium text-foreground"
- numberOfLines={Platform.OS === "android" ? 2 : 1}
- >
- {props.option.label}
- </Text>
- {props.option.isDefault ? (
- <View className="rounded-md bg-subtle-strong px-1.5 py-0.5">
- <Text className="text-3xs font-t3-bold text-foreground-muted">Default</Text>
- </View>
- ) : null}
- {props.option.isLegacy ? (
- <View className="rounded-md bg-subtle px-1.5 py-0.5">
- <Text className="text-3xs font-t3-bold text-foreground-muted">Legacy</Text>
- </View>
- ) : null}
- {props.option.isUnavailable ? (
- <Text className="text-xs text-foreground">Unavailable</Text>
- ) : null}
- </View>
- {props.option.subtitle ? (
- <Text
- className="text-xs text-foreground-muted"
- numberOfLines={Platform.OS === "android" ? 2 : 1}
- >
- {props.option.subtitle}
- </Text>
- ) : null}
- </View>
- {props.selected && Platform.OS !== "android" ? (
- <SymbolView
- name="checkmark"
- size={16}
- tintColorClassName="accent-icon"
- type="monochrome"
- weight="semibold"
- />
- ) : null}
- </Pressable>
- <Pressable
- accessibilityLabel={`${props.isFavorite ? "Remove from" : "Add to"} favorites: ${
- props.option.providerLabel
- }, ${props.option.label}`}
- accessibilityRole="button"
- accessibilityState={{ disabled: !props.favoritesLoaded, selected: props.isFavorite }}
- className="min-h-11 min-w-11 items-center justify-center"
- disabled={!props.favoritesLoaded}
- onPress={props.onToggleFavorite}
- >
- <SymbolView
- name={props.isFavorite ? "star.fill" : "star"}
- size={18}
- tintColorClassName={props.isFavorite ? "accent-icon" : "accent-icon-subtle"}
- type="monochrome"
- />
- </Pressable>
- </View>
- );
-}
-
/** Provider catalog header with its harness logo and disclosure state. */
function ProviderHeader(props: {
readonly driver: string | undefined;
@@ -296,46 +201,6 @@ function DisclosureRow(props: {
);
}
-/** Single option inside a submenu panel. */
-function ChoiceRow(props: {
- readonly label: string;
- readonly description?: string;
- readonly selected: boolean;
- readonly onPress: () => void;
- readonly isLast: boolean;
-}) {
- return (
- <Pressable
- accessibilityLabel={props.description ? `${props.label}. ${props.description}` : props.label}
- accessibilityRole="radio"
- accessibilityState={{ checked: props.selected }}
- onPress={props.onPress}
- style={Platform.OS === "android" ? { minHeight: 56 } : undefined}
- className={cn(
- "min-h-14 flex-row items-center gap-3 bg-card px-4 py-3 active:bg-subtle",
- !props.isLast && "border-b border-border-subtle",
- )}
- >
- {Platform.OS === "android" ? <MaterialRadioIndicator selected={props.selected} /> : null}
- <View className="min-w-0 flex-1 gap-0.5">
- <Text className="text-base font-t3-medium text-foreground">{props.label}</Text>
- {props.description ? (
- <Text className="text-sm leading-5 text-foreground-muted">{props.description}</Text>
- ) : null}
- </View>
- {props.selected && Platform.OS !== "android" ? (
- <SymbolView
- name="checkmark"
- size={16}
- tintColorClassName="accent-icon"
- type="monochrome"
- weight="semibold"
- />
- ) : null}
- </Pressable>
- );
-}
-
function SwitchRow(props: {
readonly label: string;
readonly value: boolean;