Skip to content

Commit 2bcc5cc

Browse files
fix(mobile): standardize shared button states and adoption (pingdotgg#18530)
1 parent b089f95 commit 2bcc5cc

23 files changed

Lines changed: 431 additions & 410 deletions

apps/mobile/src/components/MaterialButton.android.tsx renamed to apps/mobile/src/components/Button.android.tsx

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { SymbolView } from "./AppSymbol";
12
import {
23
Box,
3-
Button,
4+
Button as ComposeButton,
45
LoadingIndicator,
56
FilledTonalButton,
67
Host,
78
Row,
9+
RNHostView,
810
Text,
911
TextButton,
1012
} from "@expo/ui/jetpack-compose";
@@ -13,37 +15,42 @@ import { View } from "react-native";
1315

1416
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
1517
import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
16-
import type { MaterialButtonProps } from "./MaterialButton";
18+
import type { ButtonProps } from "./Button";
1719
import { useAndroidControlSizing } from "./useAndroidControlSizing";
1820

19-
export function MaterialButton(props: MaterialButtonProps) {
21+
export function Button(props: ButtonProps) {
2022
const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
2123
const typography = useScaledTextRole("footnote");
2224
const { scale, mediumIconSize } = useAndroidControlSizing();
2325
const tone = props.tone ?? "secondary";
2426
const Component =
25-
tone === "text" ? TextButton : tone === "secondary" ? FilledTonalButton : Button;
27+
tone === "text" ? TextButton : tone === "secondary" ? FilledTonalButton : ComposeButton;
2628
const containerColor =
27-
tone === "primary"
28-
? colors["--color-primary"]
29-
: tone === "danger"
30-
? colors["--color-danger"]
31-
: tone === "text"
32-
? "#00000000"
33-
: colors["--color-secondary"];
29+
tone === "contrast"
30+
? colors["--color-foreground"]
31+
: tone === "primary"
32+
? colors["--color-primary"]
33+
: tone === "danger"
34+
? colors["--color-danger"]
35+
: tone === "text"
36+
? "#00000000"
37+
: colors["--color-secondary"];
3438
const contentColor =
35-
tone === "primary"
36-
? colors["--color-primary-foreground"]
37-
: tone === "danger"
38-
? colors["--color-danger-foreground"]
39-
: tone === "text"
40-
? colors["--color-primary-text"]
41-
: colors["--color-secondary-foreground"];
39+
tone === "contrast"
40+
? colors["--color-screen"]
41+
: tone === "primary"
42+
? colors["--color-primary-foreground"]
43+
: tone === "danger"
44+
? colors["--color-danger-foreground"]
45+
: tone === "text"
46+
? colors["--color-primary-text"]
47+
: colors["--color-secondary-foreground"];
4248
return (
4349
<View
4450
accessible
4551
accessibilityRole="button"
4652
accessibilityLabel={props.label}
53+
accessibilityHint={props.accessibilityHint}
4754
accessibilityState={{
4855
disabled: Boolean(props.disabled || props.loading),
4956
busy: Boolean(props.loading),
@@ -84,6 +91,21 @@ export function MaterialButton(props: MaterialButtonProps) {
8491
/>
8592
<Box modifiers={[size(8 * scale, 1)]} />
8693
</>
94+
) : props.icon ? (
95+
<>
96+
<RNHostView matchContents modifiers={[size(mediumIconSize, mediumIconSize)]}>
97+
<View style={{ width: mediumIconSize, height: mediumIconSize }}>
98+
<SymbolView
99+
name={props.icon}
100+
size={mediumIconSize}
101+
tintColor={
102+
props.disabled ? colors["--color-foreground-muted"] : contentColor
103+
}
104+
/>
105+
</View>
106+
</RNHostView>
107+
<Box modifiers={[size(8 * scale, 1)]} />
108+
</>
87109
) : null}
88110
<Text style={{ ...typography, fontWeight: "500" }}>{props.label}</Text>
89111
</Row>

apps/mobile/src/components/MaterialButton.tsx renamed to apps/mobile/src/components/Button.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import { SymbolView, type AppSymbolName } from "./AppSymbol";
12
import { Pressable } from "react-native";
3+
import { AppActivityIndicator } from "./AppActivityIndicator";
24
import { AppText } from "./AppText";
35
import { cn } from "../lib/cn";
46

5-
export interface MaterialButtonProps {
7+
export interface ButtonProps {
68
readonly label: string;
9+
readonly icon?: AppSymbolName;
710
readonly onPress: () => void;
811
readonly disabled?: boolean;
12+
readonly accessibilityHint?: string;
913
readonly loading?: boolean;
1014
readonly tone?: "primary" | "secondary" | "danger" | "text" | "contrast";
1115
readonly fullWidth?: boolean;
@@ -19,24 +23,37 @@ const TONE_CLASS_NAMES = {
1923
text: ["bg-transparent", "text-primary-text"],
2024
} as const;
2125

22-
export function MaterialButton(props: MaterialButtonProps) {
26+
export function Button(props: ButtonProps) {
2327
const [containerClassName, labelClassName] = TONE_CLASS_NAMES[props.tone ?? "secondary"];
2428
const disabled = Boolean(props.disabled || props.loading);
2529
return (
2630
<Pressable
2731
accessibilityRole="button"
28-
accessibilityState={{ disabled }}
32+
accessibilityLabel={props.label}
33+
accessibilityHint={props.accessibilityHint}
34+
accessibilityState={{ disabled, busy: Boolean(props.loading) }}
2935
disabled={disabled}
3036
onPress={props.onPress}
3137
className={cn(
32-
"min-h-12 justify-center rounded-full px-6 active:opacity-70",
38+
"min-h-12 flex-row items-center justify-center gap-2 rounded-full px-6 active:opacity-70",
3339
props.fullWidth ? "w-full" : "self-start",
3440
disabled ? "bg-subtle-strong" : containerClassName,
3541
)}
3642
>
43+
{props.loading ? (
44+
<AppActivityIndicator colorClassName="accent-foreground-muted" />
45+
) : props.icon ? (
46+
<SymbolView
47+
name={props.icon}
48+
size={18}
49+
tintColorClassName={
50+
disabled ? "accent-foreground-muted" : labelClassName.replace("text-", "accent-")
51+
}
52+
/>
53+
) : null}
3754
<AppText
3855
className={cn(
39-
"text-center font-t3-medium",
56+
"min-w-0 shrink text-center font-t3-medium",
4057
disabled ? "text-foreground-muted" : labelClassName,
4158
)}
4259
>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { cn } from "../lib/cn";
44
import { SymbolView } from "./AppSymbol";
55
import { AppText as Text } from "./AppText";
66
import { MaterialIconButton } from "./MaterialIconButton";
7-
import { MaterialButton } from "./MaterialButton";
7+
import { Button } from "./Button";
88
import { useAndroidControlSizing } from "./useAndroidControlSizing";
99

1010
export { ControlPillMenu } from "./ControlPillMenu";
@@ -91,7 +91,7 @@ export function ControlPill(props: {
9191
(!props.accessibilityLabel || props.accessibilityLabel === props.label)
9292
) {
9393
return (
94-
<MaterialButton
94+
<Button
9595
label={props.label}
9696
onPress={props.onPress}
9797
disabled={props.disabled}

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Pressable, View } from "react-native";
1+
import { View } from "react-native";
22
import type { ReactNode } from "react";
33

44
import { AppText as Text } from "./AppText";
5+
import { Button } from "./Button";
56

67
export function EmptyState(props: {
78
readonly title: string;
@@ -21,14 +22,9 @@ export function EmptyState(props: {
2122
{props.action ? (
2223
<View className="mt-5">{props.action}</View>
2324
) : props.actionLabel && props.onAction ? (
24-
<Pressable
25-
className="mt-5 rounded-full bg-primary px-5 py-3 active:opacity-70"
26-
onPress={props.onAction}
27-
>
28-
<Text className="text-sm font-t3-bold text-primary-foreground">
29-
{props.actionLabel}
30-
</Text>
31-
</Pressable>
25+
<View className="mt-5">
26+
<Button tone="primary" label={props.actionLabel} onPress={props.onAction} />
27+
</View>
3228
) : null}
3329
</View>
3430
);
@@ -43,12 +39,9 @@ export function EmptyState(props: {
4339
{props.action ? (
4440
<View className="mt-4 self-start">{props.action}</View>
4541
) : props.actionLabel && props.onAction ? (
46-
<Pressable
47-
className="mt-4 self-start rounded-full bg-primary px-4 py-2.5 active:opacity-70"
48-
onPress={props.onAction}
49-
>
50-
<Text className="text-sm font-t3-bold text-primary-foreground">{props.actionLabel}</Text>
51-
</Pressable>
42+
<View className="mt-4 self-start">
43+
<Button tone="primary" label={props.actionLabel} onPress={props.onAction} />
44+
</View>
5245
) : null}
5346
</View>
5447
);

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, type ReactNode } from "react";
22
import { ScrollView, View } from "react-native";
33

44
import { AppText as Text } from "./AppText";
5-
import { MaterialButton } from "./MaterialButton";
5+
import { Button } from "./Button";
66
import { copyTextWithHaptic } from "../lib/copyTextWithHaptic";
77

88
interface RenderErrorBoundaryProps {
@@ -107,19 +107,14 @@ export function RenderFailureView(
107107
{props.details.split("\n", 1)[0]?.slice(0, 300)}
108108
</Text>
109109
<View className="w-full max-w-xs gap-2">
110-
<MaterialButton label="Try again" onPress={props.retry} tone="primary" fullWidth />
111-
<MaterialButton
110+
<Button label="Try again" onPress={props.retry} tone="primary" fullWidth />
111+
<Button
112112
label="Copy details"
113113
onPress={() => copyTextWithHaptic(props.details, { target: "error details" })}
114114
fullWidth
115115
/>
116116
{props.exit ? (
117-
<MaterialButton
118-
label={props.exit.label}
119-
onPress={props.exit.onPress}
120-
tone="text"
121-
fullWidth
122-
/>
117+
<Button label={props.exit.label} onPress={props.exit.onPress} tone="text" fullWidth />
123118
) : null}
124119
</View>
125120
</ScrollView>

‎apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanim
1111

1212
import { AppText as Text } from "../../components/AppText";
1313
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
14-
import { MaterialButton } from "../../components/MaterialButton";
14+
import { Button } from "../../components/Button";
1515
import { MaterialIconButton } from "../../components/MaterialIconButton";
1616
import { ThemedSwitch } from "../../components/ThemedSwitch";
1717
import { cn } from "../../lib/cn";
@@ -185,7 +185,7 @@ export function ConnectionEnvironmentRow(props: {
185185
<View className="flex-row items-center justify-end gap-2">
186186
{props.environment.isRelayManaged ? null : (
187187
<View className="flex-1">
188-
<MaterialButton
188+
<Button
189189
label="Save"
190190
tone="primary"
191191
fullWidth

‎apps/mobile/src/features/projects/AddProjectScreen.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ vi.mock("react", async (importOriginal) => ({
2525
useEffect: () => {},
2626
}));
2727
vi.mock("../../components/MaterialListRow", () => ({ MaterialListRow: "MaterialListRow" }));
28-
vi.mock("../../components/MaterialButton", () => ({ MaterialButton: "MaterialButton" }));
28+
vi.mock("../../components/Button", () => ({ Button: "Button" }));
2929
vi.mock("../../components/ScreenScrollView", () => ({ ScreenScrollView: "ScrollView" }));
3030
vi.mock("../settings/components/SettingsScreen", () => ({ SettingsScreen: "SettingsScreen" }));
3131
vi.mock("../../components/ThemedSwitch", () => ({ ThemedSwitch: "Switch" }));

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AppActivityIndicator } from "../../components/AppActivityIndicator";
22
import { MaterialListRow } from "../../components/MaterialListRow";
33
import { SettingsScreen } from "../settings/components/SettingsScreen";
44
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
5-
import { MaterialButton } from "../../components/MaterialButton";
5+
import { Button } from "../../components/Button";
66
import {
77
addProjectRemoteSourceLabel,
88
addProjectRemoteSourcePathHint,
@@ -263,7 +263,7 @@ function PrimaryActionButton(props: {
263263
readonly loading?: boolean;
264264
readonly onPress: () => void;
265265
}) {
266-
if (Platform.OS === "android") return <MaterialButton {...props} tone="primary" fullWidth />;
266+
if (Platform.OS === "android") return <Button {...props} tone="primary" fullWidth />;
267267
return (
268268
<Pressable
269269
disabled={props.disabled}

‎apps/mobile/src/features/pull-requests/PullRequestControls.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Platform, Pressable, View } from "react-native";
77
import { useSafeAreaInsets } from "react-native-safe-area-context";
88
import { AppText as Text } from "../../components/AppText";
99
import { SymbolView, type AppSymbolName } from "../../components/AppSymbol";
10-
import { MaterialButton } from "../../components/MaterialButton";
10+
import { Button } from "../../components/Button";
1111
import { MaterialIconButton } from "../../components/MaterialIconButton";
1212
import { MaterialFloatingToolbar } from "./MaterialFloatingToolbar";
1313
import { ControlPillMenu } from "../../components/ControlPillMenu";
@@ -137,7 +137,7 @@ export function PullRequestActionToolbar(props: {
137137
const showPrimary = pendingReview || canOpenThread;
138138
if (Platform.OS === "android") {
139139
const primary = (
140-
<MaterialButton
140+
<Button
141141
label={primaryLabel}
142142
tone="primary"
143143
disabled={primaryDisabled}

‎apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeS
99
import { useSafeAreaInsets } from "react-native-safe-area-context";
1010
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
1111
import { AndroidScreenHeader } from "../../components/AndroidScreenHeader";
12-
import { MaterialButton } from "../../components/MaterialButton";
12+
import { Button } from "../../components/Button";
1313
import { GlassSurface } from "../../components/GlassSurface";
1414
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
1515
import { relativeTime } from "../../lib/time";
@@ -174,7 +174,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
174174
{thread.isResolved ? "Resolved" : "Unresolved"}
175175
{thread.isOutdated ? " · Outdated" : ""}
176176
</Text>
177-
<MaterialButton
177+
<Button
178178
label="View file diff"
179179
onPress={() =>
180180
navigation.navigate("PullRequestFile", { ...params, path: thread.path })
@@ -199,7 +199,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
199199
</View>
200200
))}
201201
{nextCursor ? (
202-
<MaterialButton
202+
<Button
203203
label={busy ? "Loading…" : "Load more replies"}
204204
disabled={busy}
205205
onPress={() => void more()}
@@ -232,7 +232,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
232232
className="max-h-36 min-h-12 min-w-0 flex-1 rounded-[24px] border-0 bg-transparent px-4 py-3 text-base text-foreground"
233233
/>
234234
<View>
235-
<MaterialButton
235+
<Button
236236
label={busy ? "Posting…" : "Reply"}
237237
tone="contrast"
238238
disabled={busy || !body.trim()}

0 commit comments

Comments
 (0)