@devries-cameron20 / t3code Mirror · read-only / commits / 505ccfd0e4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 09:15 UTC

fix(mobile): route alerts through the themed dialog presenter (#19997)

Julius Marminge committed Oct 15, 2026 at 15:46 UTC 505ccfd0e45004c17d1fb4d3c8fc77bd14fe0989
4 files changed +138 -26
apps/mobile/assets/icons/delete.xml new
+5
@@ -0,0 +1,5 @@
1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
2 + android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
3 + <path android:fillColor="#FFFFFFFF" android:fillType="evenOdd"
4 + android:pathData="M9,3 H15 V5 H21 V7 H19 V21 H5 V7 H3 V5 H9 Z M11,5 H13 V4.75 H11 Z M7,7 V19 H17 V7 Z M9,9 H11 V17 H9 Z M13,9 H15 V17 H13 Z" />
5 +</vector>
apps/mobile/src/components/Dialog.android.tsx
+114 -26
@@ -1,9 +1,13 @@
1 import { NativeThemeHost } from "./NativeThemeHost.android";
2 import {
3 AlertDialog,
4 + Button,
5 + OutlinedButton,
6 + Icon,
7 + FlowRow,
8 + Column,
9 OutlinedTextField,
10 Text,
6 - TextButton,
11 useNativeState,
12 } from "@expo/ui/jetpack-compose";
13
@@ -11,16 +15,37 @@ import { useAppearancePreferences } from "../features/settings/appearance/Appear
15 import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
16
17 import { useCallback, useEffect, useRef, useState } from "react";
18 +import { themeColorWithContrast } from "../lib/mobileTheme";
19 +import type { Alert, AlertButton } from "react-native";
20 import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
21
22 export type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
23
24 +type AlertRequest = {
25 + readonly title: Parameters<typeof Alert.alert>[0];
26 + readonly message: Parameters<typeof Alert.alert>[1];
27 + readonly buttons: Parameters<typeof Alert.alert>[2];
28 + readonly options: Parameters<typeof Alert.alert>[3];
29 +};
30 +
31 type DialogRequest =
32 + | { readonly kind: "alert"; readonly request: AlertRequest }
33 | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }
34 | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };
35
36 let presentRequest: ((request: DialogRequest) => void) | null = null;
37
38 +export function alert(...[title, message, buttons, options]: Parameters<typeof Alert.alert>): void {
39 + const actions = buttons?.length ? buttons.slice(0, 3) : [{ text: "OK" }];
40 + const normalized = actions.map((action, index) =>
41 + index === actions.length - 1 ? { ...action, text: action.text || "OK" } : action,
42 + );
43 + presentRequest?.({
44 + kind: "alert",
45 + request: { title, message, buttons: normalized, options },
46 + });
47 +}
48 +
49 export function confirm(request: ConfirmDialogRequest): void {
50 presentRequest?.({ kind: "confirm", request });
51 }
@@ -29,7 +54,7 @@ export function prompt(request: TextInputDialogRequest): void {
54 presentRequest?.({ kind: "text-input", request });
55 }
56
32 -/** Android presenter for Dialog.confirm and Dialog.prompt; mounted once at the app root. */
57 +/** Android presenter for Dialog.alert, Dialog.confirm and Dialog.prompt; mounted once at the app root. */
58 export function Host() {
59 const [presented, setPresented] = useState<(DialogRequest & { readonly id: number }) | null>(
60 null,
@@ -48,7 +73,8 @@ export function Host() {
73
74 const handleCancel = useCallback(() => {
75 setPresented(null);
51 - presented?.request.onCancel?.();
76 + if (presented?.kind === "alert") presented.request.options?.onDismiss?.();
77 + else presented?.request.onCancel?.();
78 }, [presented]);
79
80 const handleConfirm = useCallback(
@@ -63,6 +89,27 @@ export function Host() {
89 [inputValue, presented],
90 );
91
92 + if (presented?.kind === "alert") {
93 + return (
94 + <DialogPresentation
95 + key={presented.id}
96 + request={{
97 + title: presented.request.title ?? "",
98 + message: presented.request.message ?? undefined,
99 + confirmText: "",
100 + }}
101 + alertActions={presented.request.buttons ?? [{ text: "OK" }]}
102 + dismissable={presented.request.options?.cancelable ?? false}
103 + onAlertAction={(action) => {
104 + setPresented(null);
105 + action.onPress?.();
106 + }}
107 + onCancel={handleCancel}
108 + onConfirm={handleConfirm}
109 + />
110 + );
111 + }
112 +
113 return presented ? (
114 <DialogPresentation
115 key={presented.id}
@@ -88,19 +135,68 @@ function DialogPresentation(props: DialogPresentationProps) {
135 const value = props.inputInitialValue === undefined ? undefined : inputState.get();
136 props.onConfirm(value);
137 };
138 + const actions = props.alertActions ?? [
139 + { text: props.request.cancelText ?? "Cancel", onPress: props.onCancel },
140 + {
141 + text: props.request.confirmText,
142 + style: props.request.destructive ? ("destructive" as const) : ("default" as const),
143 + onPress: confirm,
144 + },
145 + ];
146 + const destructive = actions.some((action) => action.style === "destructive");
147 + // Error text colors can be pastel in dark themes. Filled actions need a white-label contrast pair.
148 + const destructiveFill = themeColorWithContrast(colors["--color-danger-foreground"], "#ffffff");
149 + const renderAction = (action: AlertButton, index: number) => {
150 + const isDestructive = action.style === "destructive";
151 + const isPrimary = isDestructive || index === actions.length - 1;
152 + const Component = isPrimary ? Button : OutlinedButton;
153 + return (
154 + <Component
155 + key={index}
156 + onClick={() => (props.alertActions ? props.onAlertAction?.(action) : action.onPress?.())}
157 + colors={{
158 + containerColor: isDestructive
159 + ? destructiveFill
160 + : isPrimary
161 + ? colors["--color-prominent-action"]
162 + : "#00000000",
163 + contentColor: isDestructive
164 + ? "#ffffff"
165 + : isPrimary
166 + ? colors["--color-prominent-action-foreground"]
167 + : colors["--color-foreground"],
168 + }}
169 + >
170 + <Text style={bodyTypography}>{action.text ?? ""}</Text>
171 + </Component>
172 + );
173 + };
174 return (
175 <NativeThemeHost ignoreSafeAreaKeyboardInsets style={{ height: 0, width: 0 }}>
176 <AlertDialog
177 onDismissRequest={props.onCancel}
178 + properties={{
179 + dismissOnBackPress: props.dismissable ?? true,
180 + dismissOnClickOutside: props.dismissable ?? true,
181 + }}
182 tonalElevation={0}
183 colors={{
97 - containerColor: colors["--color-card-alt"],
184 + containerColor: colors["--color-card"],
185 titleContentColor: colors["--color-foreground"],
186 textContentColor: colors["--color-foreground-secondary"],
187 }}
188 >
189 <AlertDialog.Title>
103 - <Text style={titleTypography}>{props.request.title}</Text>
190 + <Column verticalArrangement={{ spacedBy: 16 }}>
191 + {destructive ? (
192 + <Icon
193 + source={require("../../assets/icons/delete.xml")}
194 + tint={colors["--color-danger-foreground"]}
195 + size={24}
196 + />
197 + ) : null}
198 + <Text style={titleTypography}>{props.request.title}</Text>
199 + </Column>
200 </AlertDialog.Title>
201 {props.inputInitialValue !== undefined ? (
202 <AlertDialog.Text>
@@ -133,33 +229,25 @@ function DialogPresentation(props: DialogPresentationProps) {
229 <Text style={bodyTypography}>{props.request.message}</Text>
230 </AlertDialog.Text>
231 ) : null}
136 - <AlertDialog.DismissButton>
137 - <TextButton
138 - onClick={props.onCancel}
139 - colors={{ contentColor: colors["--color-primary-text"] }}
140 - >
141 - <Text style={bodyTypography}>{props.request.cancelText ?? "Cancel"}</Text>
142 - </TextButton>
143 - </AlertDialog.DismissButton>
144 - <AlertDialog.ConfirmButton>
145 - <TextButton
146 - onClick={confirm}
147 - colors={{
148 - contentColor:
149 - colors[
150 - props.request.destructive ? "--color-danger-foreground" : "--color-primary-text"
151 - ],
152 - }}
153 - >
154 - <Text style={bodyTypography}>{props.request.confirmText}</Text>
155 - </TextButton>
156 - </AlertDialog.ConfirmButton>
232 + {actions.length > 1 ? (
233 + <AlertDialog.DismissButton>
234 + <FlowRow>{actions.slice(0, -1).map(renderAction)}</FlowRow>
235 + </AlertDialog.DismissButton>
236 + ) : null}
237 + {actions.length > 0 ? (
238 + <AlertDialog.ConfirmButton>
239 + {renderAction(actions[actions.length - 1]!, actions.length - 1)}
240 + </AlertDialog.ConfirmButton>
241 + ) : null}
242 </AlertDialog>
243 </NativeThemeHost>
244 );
245 }
246
247 interface DialogPresentationProps {
248 + readonly alertActions?: readonly AlertButton[];
249 + readonly onAlertAction?: (action: AlertButton) => void;
250 + readonly dismissable?: boolean;
251 readonly request: Pick<
252 ConfirmDialogRequest,
253 "title" | "message" | "cancelText" | "confirmText" | "destructive"
apps/mobile/src/components/Dialog.tsx renamed
+5
@@ -3,6 +3,11 @@ import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.type
3
4 export type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
5
6 +/** Informational and multi-action alerts share the same platform presenter. */
7 +export function alert(...args: Parameters<typeof Alert.alert>): void {
8 + Alert.alert(...args);
9 +}
10 +
11 export function confirm(request: ConfirmDialogRequest): void {
12 Alert.alert(request.title, request.message, [
13 { text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },
apps/mobile/src/features/development/ComponentCatalogScreen.tsx
+14
@@ -224,6 +224,20 @@ export function ComponentCatalogScreen() {
224 <View className="flex-row flex-wrap gap-2">
225 <Button label="Sheet" onPress={() => setSheet(true)} />
226 <Button label="Dialog" onPress={confirm} />
227 + <Button
228 + label="Alert"
229 + onPress={() =>
230 + Dialog.alert("Example alert", "Choose an action.", [
231 + {
232 + text: "More info",
233 + onPress: () =>
234 + Dialog.alert("More information", "This second alert stays open."),
235 + },
236 + { text: "Cancel", style: "cancel" },
237 + { text: "Continue", onPress: announceAction },
238 + ])
239 + }
240 + />
241 <Button
242 label="Prompt"
243 onPress={() =>