Skip to content

Commit ee3c64c

Browse files
refactor(mobile): share settings action rows
1 parent 48595c7 commit ee3c64c

3 files changed

Lines changed: 53 additions & 63 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Platform } from "react-native";
2+
import { useResolveClassNames } from "uniwind";
3+
4+
import { AppActivityIndicator } from "./AppActivityIndicator";
5+
import { ListRowLayout, type ListRowContentProps } from "./ListRowLayout";
6+
import { RowPressable } from "./RowPressable";
7+
8+
export function ListActionRow(
9+
props: ListRowContentProps & {
10+
readonly tone?: "default" | "danger";
11+
readonly loading?: boolean;
12+
readonly onPress: () => void;
13+
},
14+
) {
15+
const rippleStyle = useResolveClassNames("bg-subtle-strong");
16+
const disabled = Boolean(props.disabled || props.loading);
17+
return (
18+
<RowPressable
19+
accessibilityRole="button"
20+
accessibilityLabel={props.label}
21+
accessibilityHint={props.description}
22+
accessibilityState={{ disabled, busy: Boolean(props.loading) }}
23+
disabled={disabled}
24+
onPress={props.onPress}
25+
android_ripple={{ color: rippleStyle.backgroundColor }}
26+
unstable_pressDelay={Platform.OS === "android" ? 50 : undefined}
27+
className="bg-grouped-card"
28+
>
29+
<ListRowLayout
30+
{...props}
31+
disabled={disabled}
32+
accessory={
33+
props.loading ? (
34+
<AppActivityIndicator
35+
colorClassName={props.tone === "danger" ? "accent-danger-foreground" : "accent-icon"}
36+
/>
37+
) : undefined
38+
}
39+
/>
40+
</RowPressable>
41+
);
42+
}

‎apps/mobile/src/components/ListRowLayout.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export function ListRowLayout({
2121
detail,
2222
disabled,
2323
accessory,
24-
}: ListRowContentProps & { readonly accessory?: ReactNode }) {
24+
tone = "default",
25+
}: ListRowContentProps & { readonly accessory?: ReactNode; readonly tone?: "default" | "danger" }) {
2526
const { fontScale } = useWindowDimensions();
2627
// Leave the label room to wrap at accessibility text sizes.
2728
const stackDetail = fontScale >= 1.5;
@@ -38,14 +39,20 @@ export function ListRowLayout({
3839
<SymbolView
3940
name={icon}
4041
size={Platform.OS === "android" ? 24 : 22}
41-
tintColorClassName="accent-icon"
42+
tintColorClassName={tone === "danger" ? "accent-danger-foreground" : "accent-icon"}
4243
type="monochrome"
4344
weight="regular"
4445
/>
4546
</View>
4647
) : null}
4748
<View className="min-w-0 flex-1 gap-1">
48-
<AppText className="text-base text-foreground">{label}</AppText>
49+
<AppText
50+
className={
51+
tone === "danger" ? "text-base text-danger-foreground" : "text-base text-foreground"
52+
}
53+
>
54+
{label}
55+
</AppText>
4956
{description ? (
5057
<AppText className="text-sm text-foreground-muted">{description}</AppText>
5158
) : null}
Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1 @@
1-
import type { ComponentProps } from "react";
2-
import { Platform, Pressable } from "react-native";
3-
4-
import { AppActivityIndicator } from "../../../components/AppActivityIndicator";
5-
import { SymbolView } from "../../../components/AppSymbol";
6-
import { AppText as Text } from "../../../components/AppText";
7-
import { MaterialListRow } from "../../../components/MaterialListRow";
8-
import { cn } from "../../../lib/cn";
9-
10-
export function SettingsActionRow(props: {
11-
readonly icon: ComponentProps<typeof SymbolView>["name"];
12-
readonly label: string;
13-
readonly tone?: "default" | "danger";
14-
readonly disabled?: boolean;
15-
readonly loading?: boolean;
16-
readonly onPress: () => void;
17-
}) {
18-
const danger = props.tone === "danger";
19-
const textClassName = danger ? "tabular-nums text-danger-foreground" : "text-foreground";
20-
const iconColorClassName = danger ? "accent-danger-foreground" : "accent-icon";
21-
const icon = (
22-
<SymbolView
23-
name={props.icon}
24-
size={Platform.OS === "android" ? 24 : 22}
25-
tintColorClassName={iconColorClassName}
26-
type="monochrome"
27-
weight="regular"
28-
/>
29-
);
30-
const spinner = props.loading ? (
31-
<AppActivityIndicator colorClassName={iconColorClassName} />
32-
) : null;
33-
34-
if (Platform.OS === "android") {
35-
return (
36-
<MaterialListRow
37-
className="bg-grouped-card"
38-
title={props.label}
39-
titleClassName={textClassName}
40-
leading={icon}
41-
trailing={spinner}
42-
disabled={props.disabled}
43-
onPress={props.onPress}
44-
/>
45-
);
46-
}
47-
48-
return (
49-
<Pressable
50-
accessibilityRole="button"
51-
disabled={props.disabled}
52-
onPress={props.onPress}
53-
className="flex-row items-center gap-4 p-4 disabled:opacity-40"
54-
>
55-
{icon}
56-
<Text className={cn("flex-1 text-lg", textClassName)}>{props.label}</Text>
57-
{spinner}
58-
</Pressable>
59-
);
60-
}
1+
export { ListActionRow as SettingsActionRow } from "../../../components/ListActionRow";

0 commit comments

Comments
 (0)