@devries-cameron20 / t3code-1 / commits / 8d2e919c15
Fork 0

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

refactor(mobile): centralize dialog and sheet APIs (#19266)

Julius Marminge committed Oct 15, 2026 at 15:46 UTC 8d2e919c15d93ad8bdcfe370ccb18a0c69dd52b5
18 files changed +292 -366
apps/mobile/src/App.tsx
+2 -2
@@ -10,7 +10,7 @@ import { createStaticNavigation } from "@react-navigation/native";
10
11 import { RegistryContext } from "@effect/atom-react";
12 import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet";
13 -import { ConfirmDialogHost } from "./components/ConfirmDialogHost";
13 +import * as Dialog from "./components/Dialog";
14 import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";
15 import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";
16 import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider";
@@ -96,7 +96,7 @@ function AppContent() {
96 <IncomingShareProvider>
97 <Navigation linking={appLinking} theme={navigationTheme} />
98 </IncomingShareProvider>
99 - <ConfirmDialogHost />
99 + <Dialog.Host />
100 <ThreadArrangementHost />
101 </NativeLayoutMetricsProvider>
102 </GlobalVoiceInputControl>
apps/mobile/src/components/AppSheet.tsx deleted
-80
@@ -1,80 +0,0 @@
1 -import { useId, useState, type ReactNode } from "react";
2 -import { Platform, View } from "react-native";
3 -import { FormSheet, Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
4 -import { useResolveClassNames, withUniwind } from "uniwind";
5 -
6 -import { AndroidSheetHeader } from "./AndroidScreenHeader";
7 -import { nativeHeaderScrollEdgeEffects } from "../native/StackHeader";
8 -
9 -const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
10 -const NativeScreen = withUniwind(Screen);
11 -const NativeHeader = withUniwind(ScreenStackHeaderConfig, {
12 - color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },
13 - titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },
14 -});
15 -
16 -/** Native presentation for local context whose owner supplies its dismissal callback. */
17 -export function AppSheet(props: {
18 - readonly title: string;
19 - readonly children: ReactNode;
20 - readonly onClose: () => void;
21 -}) {
22 - const containerStyle = useResolveClassNames("bg-sheet");
23 - const screenId = useId();
24 - const [isOpen, setIsOpen] = useState(true);
25 - const close = () => setIsOpen(false);
26 -
27 - return (
28 - <FormSheet
29 - isOpen={isOpen}
30 - detents={[0.5, 0.9]}
31 - prefersGrabberVisible
32 - nativeContainerStyle={containerStyle}
33 - onDismiss={props.onClose}
34 - onNativeDismiss={props.onClose}
35 - >
36 - <View collapsable={false} className="flex-1 bg-sheet">
37 - {Platform.OS === "ios" ? (
38 - <ScreenStack style={{ flex: 1 }}>
39 - <NativeScreen
40 - activityState={2}
41 - enabled
42 - isNativeStack
43 - screenId={`app-sheet-${screenId}`}
44 - scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
45 - className="flex-1 bg-sheet"
46 - >
47 - {props.children}
48 - <NativeHeader
49 - backgroundColor="rgba(0,0,0,0)"
50 - tintColorClassName="accent-foreground"
51 - hideBackButton
52 - hideShadow={false}
53 - title={props.title}
54 - titleColorClassName="accent-foreground"
55 - titleFontSize={18}
56 - titleFontWeight="800"
57 - translucent
58 - headerRightBarButtonItems={[
59 - {
60 - type: "button",
61 - title: "Done",
62 - variant: "done",
63 - accessibilityLabel: `Close ${props.title}`,
64 - identifier: `app-sheet-done-${screenId}`,
65 - onPress: close,
66 - },
67 - ]}
68 - />
69 - </NativeScreen>
70 - </ScreenStack>
71 - ) : (
72 - <>
73 - <AndroidSheetHeader title={props.title} onBack={close} />
74 - {props.children}
75 - </>
76 - )}
77 - </View>
78 - </FormSheet>
79 - );
80 -}
apps/mobile/src/components/ComposerContextSheet.tsx
+3 -3
@@ -24,7 +24,7 @@ import { FilePreviewModal } from "./FilePreviewModal";
24 import { VideoPreviewModal } from "./VideoPreviewModal";
25 import { ComposerContextAttachment } from "./ComposerContextAttachment";
26 import { AppText as Text } from "./AppText";
27 -import { AppSheet } from "./AppSheet";
27 +import { Sheet } from "./Sheet";
28 import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
29 import { getMobileTerminalTheme } from "../features/terminal/terminalTheme";
30
@@ -183,7 +183,7 @@ export function ComposerContextSheet(props: {
183 : undefined;
184 const terminal = record?.kind === "terminal" && !("payload" in record) ? record : null;
185 return (
186 - <AppSheet title={terminal?.terminalLabel ?? props.label} onClose={props.onClose}>
186 + <Sheet title={terminal?.terminalLabel ?? props.label} onClose={props.onClose}>
187 <ScrollView
188 className="flex-1"
189 contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
@@ -390,6 +390,6 @@ export function ComposerContextSheet(props: {
390 </Pressable>
391 ) : null}
392 </ScrollView>
393 - </AppSheet>
393 + </Sheet>
394 );
395 }
apps/mobile/src/components/ConfirmDialogHost.tsx deleted
-152
@@ -1,152 +0,0 @@
1 -import { useCallback, useEffect, useState } from "react";
2 -import { Platform, Modal, Pressable, TextInput, View } from "react-native";
3 -
4 -import { cn } from "../lib/cn";
5 -import { AppText } from "./AppText";
6 -import { MaterialConfirmDialog } from "./MaterialConfirmDialog";
7 -import type { ConfirmDialogRequest, TextInputDialogRequest } from "./ConfirmDialog.types";
8 -
9 -export type { ConfirmDialogRequest, TextInputDialogRequest } from "./ConfirmDialog.types";
10 -
11 -type DialogRequest =
12 - | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }
13 - | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };
14 -
15 -let presentRequest: ((request: DialogRequest) => void) | null = null;
16 -
17 -/**
18 - * Imperative confirm dialog, Alert.alert-shaped. Native iOS alerts already
19 - * match the app (and support per-button destructive red), so this is for
20 - * Android, where the native dialog can only theme all confirm buttons at
21 - * once. Requires ConfirmDialogHost to be mounted at the app root.
22 - */
23 -export function showConfirmDialog(request: ConfirmDialogRequest): void {
24 - presentRequest?.({ kind: "confirm", request });
25 -}
26 -
27 -export function showTextInputDialog(request: TextInputDialogRequest): void {
28 - presentRequest?.({ kind: "text-input", request });
29 -}
30 -
31 -/**
32 - * Android-style alert dialog matching the native one themed by
33 - * withAndroidModernAlertDialog — left-aligned text, right-aligned text
34 - * buttons — with what the native theme can't do: a per-dialog destructive
35 - * button color and a dimmer message than the title.
36 - */
37 -export function ConfirmDialogHost() {
38 - const [presented, setPresented] = useState<DialogRequest | null>(null);
39 - const [inputValue, setInputValue] = useState("");
40 - useEffect(() => {
41 - presentRequest = (request) => {
42 - setInputValue(request.kind === "text-input" ? request.request.initialValue : "");
43 - setPresented(request);
44 - };
45 - return () => {
46 - presentRequest = null;
47 - };
48 - }, []);
49 -
50 - const handleCancel = useCallback(() => {
51 - presented?.request.onCancel?.();
52 - setPresented(null);
53 - }, [presented]);
54 -
55 - const handleConfirm = useCallback(
56 - (nativeInputValue?: string) => {
57 - if (presented?.kind === "confirm") {
58 - presented.request.onConfirm();
59 - } else if (presented?.kind === "text-input") {
60 - presented.request.onConfirm(nativeInputValue ?? inputValue);
61 - }
62 - setPresented(null);
63 - },
64 - [inputValue, presented],
65 - );
66 -
67 - const confirmDisabled = presented?.kind === "text-input" && inputValue.trim().length === 0;
68 -
69 - if (Platform.OS === "android")
70 - return presented ? (
71 - <MaterialConfirmDialog
72 - key={`${presented.kind}:${presented.request.title}:${presented.kind === "text-input" ? presented.request.initialValue : ""}`}
73 - request={presented.request}
74 - inputInitialValue={
75 - presented.kind === "text-input" ? presented.request.initialValue : undefined
76 - }
77 - onInputChange={setInputValue}
78 - confirmDisabled={confirmDisabled}
79 - onCancel={handleCancel}
80 - onConfirm={handleConfirm}
81 - />
82 - ) : null;
83 -
84 - return (
85 - <Modal
86 - visible={presented !== null}
87 - transparent
88 - animationType="fade"
89 - statusBarTranslucent
90 - navigationBarTranslucent
91 - onRequestClose={handleCancel}
92 - >
93 - {presented === null ? null : (
94 - <View className="flex-1 items-center justify-center bg-backdrop px-8">
95 - <View className="w-full rounded-[24px] bg-card px-6 pb-4 pt-5">
96 - <AppText className="text-lg font-t3-medium">{presented.request.title}</AppText>
97 - {presented.kind === "confirm" && presented.request.message !== undefined ? (
98 - <AppText className="mt-2 text-sm text-foreground-secondary">
99 - {presented.request.message}
100 - </AppText>
101 - ) : null}
102 - {presented.kind === "text-input" ? (
103 - <TextInput
104 - accessibilityLabel={presented.request.title}
105 - autoFocus
106 - className="mt-4 rounded-xl border border-border bg-screen px-3 py-2.5 text-base text-foreground"
107 - onChangeText={setInputValue}
108 - onSubmitEditing={confirmDisabled ? undefined : () => handleConfirm()}
109 - returnKeyType="done"
110 - selectTextOnFocus
111 - value={inputValue}
112 - />
113 - ) : null}
114 - <View className="mt-5 flex-row justify-end gap-1">
115 - <View className="overflow-hidden rounded-full">
116 - <Pressable
117 - accessibilityRole="button"
118 - className="min-h-10 items-center justify-center px-4 active:bg-subtle"
119 - onPress={handleCancel}
120 - >
121 - <AppText className="text-base font-t3-medium">
122 - {presented.request.cancelText ?? "Cancel"}
123 - </AppText>
124 - </Pressable>
125 - </View>
126 - <View className="overflow-hidden rounded-full">
127 - <Pressable
128 - accessibilityRole="button"
129 - disabled={confirmDisabled}
130 - className="min-h-10 items-center justify-center px-4 active:bg-subtle"
131 - onPress={() => handleConfirm()}
132 - >
133 - <AppText
134 - className={cn(
135 - "text-base font-t3-medium",
136 - presented.kind === "confirm" &&
137 - presented.request.destructive &&
138 - "text-danger-foreground",
139 - confirmDisabled && "text-foreground-tertiary",
140 - )}
141 - >
142 - {presented.request.confirmText}
143 - </AppText>
144 - </Pressable>
145 - </View>
146 - </View>
147 - </View>
148 - </View>
149 - )}
150 - </Modal>
151 - );
152 -}
apps/mobile/src/components/Dialog.android.tsx renamed
+79 -5
@@ -9,9 +9,75 @@ import {
9
10 import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
11 import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
12 -import type { MaterialConfirmDialogProps } from "./MaterialConfirmDialog";
12
14 -export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {
13 +import { useCallback, useEffect, useRef, useState } from "react";
14 +import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
15 +
16 +export type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
17 +
18 +type DialogRequest =
19 + | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }
20 + | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };
21 +
22 +let presentRequest: ((request: DialogRequest) => void) | null = null;
23 +
24 +export function confirm(request: ConfirmDialogRequest): void {
25 + presentRequest?.({ kind: "confirm", request });
26 +}
27 +
28 +export function prompt(request: TextInputDialogRequest): void {
29 + presentRequest?.({ kind: "text-input", request });
30 +}
31 +
32 +/** Android presenter for Dialog.confirm and Dialog.prompt; mounted once at the app root. */
33 +export function Host() {
34 + const [presented, setPresented] = useState<(DialogRequest & { readonly id: number }) | null>(
35 + null,
36 + );
37 + const [inputValue, setInputValue] = useState("");
38 + const nextPresentationId = useRef(0);
39 + useEffect(() => {
40 + presentRequest = (request) => {
41 + setInputValue(request.kind === "text-input" ? request.request.initialValue : "");
42 + setPresented({ ...request, id: ++nextPresentationId.current });
43 + };
44 + return () => {
45 + presentRequest = null;
46 + };
47 + }, []);
48 +
49 + const handleCancel = useCallback(() => {
50 + setPresented(null);
51 + presented?.request.onCancel?.();
52 + }, [presented]);
53 +
54 + const handleConfirm = useCallback(
55 + (nativeInputValue?: string) => {
56 + setPresented(null);
57 + if (presented?.kind === "confirm") {
58 + presented.request.onConfirm();
59 + } else if (presented?.kind === "text-input") {
60 + presented.request.onConfirm(nativeInputValue ?? inputValue);
61 + }
62 + },
63 + [inputValue, presented],
64 + );
65 +
66 + return presented ? (
67 + <DialogPresentation
68 + key={presented.id}
69 + request={presented.request}
70 + inputInitialValue={
71 + presented.kind === "text-input" ? presented.request.initialValue : undefined
72 + }
73 + onInputChange={setInputValue}
74 + onCancel={handleCancel}
75 + onConfirm={handleConfirm}
76 + />
77 + ) : null;
78 +}
79 +
80 +function DialogPresentation(props: DialogPresentationProps) {
81 const { themeVariables: colors } = useAppearancePreferences();
82 const titleTypography = useScaledTextRole("title");
83 const bodyTypography = useScaledTextRole("footnote");
@@ -19,9 +85,7 @@ export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {
85 const inputState = useNativeState(props.inputInitialValue ?? "");
86 const inputSelection = useNativeState({ start: 0, end: props.inputInitialValue?.length ?? 0 });
87 const confirm = () => {
22 - if (props.confirmDisabled) return;
88 const value = props.inputInitialValue === undefined ? undefined : inputState.get();
24 - if (value !== undefined && !value.trim()) return;
89 props.onConfirm(value);
90 };
91 return (
@@ -80,7 +144,6 @@ export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {
144 <AlertDialog.ConfirmButton>
145 <TextButton
146 onClick={confirm}
83 - enabled={!props.confirmDisabled}
147 colors={{
148 contentColor:
149 colors[
@@ -95,3 +158,14 @@ export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {
158 </NativeThemeHost>
159 );
160 }
161 +
162 +interface DialogPresentationProps {
163 + readonly request: Pick<
164 + ConfirmDialogRequest,
165 + "title" | "message" | "cancelText" | "confirmText" | "destructive"
166 + >;
167 + readonly inputInitialValue?: string;
168 + readonly onInputChange?: (value: string) => void;
169 + readonly onCancel: () => void;
170 + readonly onConfirm: (inputValue?: string) => void;
171 +}
apps/mobile/src/components/Dialog.ts new
+33
@@ -0,0 +1,33 @@
1 +import { Alert } from "react-native";
2 +import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
3 +
4 +export type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";
5 +
6 +export function confirm(request: ConfirmDialogRequest): void {
7 + Alert.alert(request.title, request.message, [
8 + { text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },
9 + {
10 + text: request.confirmText,
11 + style: request.destructive ? "destructive" : "default",
12 + onPress: request.onConfirm,
13 + },
14 + ]);
15 +}
16 +
17 +export function prompt(request: TextInputDialogRequest): void {
18 + Alert.prompt(
19 + request.title,
20 + undefined,
21 + [
22 + { text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },
23 + { text: request.confirmText, onPress: (value) => request.onConfirm(value ?? "") },
24 + ],
25 + "plain-text",
26 + request.initialValue,
27 + );
28 +}
29 +
30 +/** iOS alerts are presented directly by React Native. */
31 +export function Host() {
32 + return null;
33 +}
apps/mobile/src/components/Dialog.types.ts renamed
apps/mobile/src/components/MaterialConfirmDialog.tsx deleted
-17
@@ -1,17 +0,0 @@
1 -import type { ConfirmDialogRequest } from "./ConfirmDialog.types";
2 -
3 -export interface MaterialConfirmDialogProps {
4 - readonly request: Pick<
5 - ConfirmDialogRequest,
6 - "title" | "message" | "cancelText" | "confirmText" | "destructive"
7 - >;
8 - readonly inputInitialValue?: string;
9 - readonly onInputChange?: (value: string) => void;
10 - readonly confirmDisabled?: boolean;
11 - readonly onCancel: () => void;
12 - readonly onConfirm: (inputValue?: string) => void;
13 -}
14 -
15 -export function MaterialConfirmDialog(_props: MaterialConfirmDialogProps) {
16 - return null;
17 -}
apps/mobile/src/components/Sheet.android.tsx new
+27
@@ -0,0 +1,27 @@
1 +import { useState } from "react";
2 +import { View } from "react-native";
3 +import { FormSheet } from "react-native-screens";
4 +import { useResolveClassNames } from "uniwind";
5 +import { AndroidSheetHeader } from "./AndroidScreenHeader";
6 +import type { SheetProps } from "./Sheet.types";
7 +export type { SheetProps } from "./Sheet.types";
8 +
9 +export function Sheet(props: SheetProps) {
10 + const containerStyle = useResolveClassNames("bg-sheet");
11 + const [isOpen, setIsOpen] = useState(true);
12 + return (
13 + <FormSheet
14 + isOpen={isOpen}
15 + detents={[0.5, 0.9]}
16 + prefersGrabberVisible
17 + nativeContainerStyle={containerStyle}
18 + onDismiss={props.onClose}
19 + onNativeDismiss={props.onClose}
20 + >
21 + <View collapsable={false} className="flex-1 bg-sheet">
22 + <AndroidSheetHeader title={props.title} onBack={() => setIsOpen(false)} />
23 + {props.children}
24 + </View>
25 + </FormSheet>
26 + );
27 +}
apps/mobile/src/components/Sheet.tsx new
+71
@@ -0,0 +1,71 @@
1 +import { useId, useState } from "react";
2 +import { Platform, View } from "react-native";
3 +import { FormSheet, Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
4 +import { useResolveClassNames, withUniwind } from "uniwind";
5 +
6 +import { nativeHeaderScrollEdgeEffects } from "../native/StackHeader";
7 +
8 +const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
9 +const NativeScreen = withUniwind(Screen);
10 +const NativeHeader = withUniwind(ScreenStackHeaderConfig, {
11 + color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },
12 + titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },
13 +});
14 +
15 +export type { SheetProps } from "./Sheet.types";
16 +import type { SheetProps } from "./Sheet.types";
17 +
18 +/** Native presentation. Scrollable children use automatic insets beneath the iOS header. */
19 +export function Sheet(props: SheetProps) {
20 + const containerStyle = useResolveClassNames("bg-sheet");
21 + const screenId = useId();
22 + const [isOpen, setIsOpen] = useState(true);
23 + const close = () => setIsOpen(false);
24 +
25 + return (
26 + <FormSheet
27 + isOpen={isOpen}
28 + detents={[0.5, 0.9]}
29 + prefersGrabberVisible
30 + nativeContainerStyle={containerStyle}
31 + onDismiss={props.onClose}
32 + onNativeDismiss={props.onClose}
33 + >
34 + <View collapsable={false} className="flex-1 bg-sheet">
35 + <ScreenStack style={{ flex: 1 }}>
36 + <NativeScreen
37 + activityState={2}
38 + enabled
39 + isNativeStack
40 + screenId={`app-sheet-${screenId}`}
41 + scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
42 + className="flex-1 bg-sheet"
43 + >
44 + {props.children}
45 + <NativeHeader
46 + backgroundColor="rgba(0,0,0,0)"
47 + tintColorClassName="accent-foreground"
48 + hideBackButton
49 + hideShadow={false}
50 + title={props.title}
51 + titleColorClassName="accent-foreground"
52 + titleFontSize={18}
53 + titleFontWeight="800"
54 + translucent
55 + headerRightBarButtonItems={[
56 + {
57 + type: "button",
58 + title: "Done",
59 + variant: "done",
60 + accessibilityLabel: `Close ${props.title}`,
61 + identifier: `app-sheet-done-${screenId}`,
62 + onPress: close,
63 + },
64 + ]}
65 + />
66 + </NativeScreen>
67 + </ScreenStack>
68 + </View>
69 + </FormSheet>
70 + );
71 +}
apps/mobile/src/components/Sheet.types.ts new
+7
@@ -0,0 +1,7 @@
1 +import type { ReactNode } from "react";
2 +
3 +export interface SheetProps {
4 + readonly title: string;
5 + readonly children: ReactNode;
6 + readonly onClose: () => void;
7 +}
apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx
+2 -9
@@ -11,7 +11,7 @@ import { Alert, Pressable, RefreshControl, ScrollView, Text, View } from "react-
11
12 import { AppActivityIndicator } from "../../components/AppActivityIndicator";
13 import { SymbolView } from "../../components/AppSymbol";
14 -import { showConfirmDialog } from "../../components/ConfirmDialogHost";
14 +import * as Dialog from "../../components/Dialog";
15 import { Menu } from "../../components/Menu";
16 import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
17 import { useAtomCommand } from "../../state/use-atom-command";
@@ -38,14 +38,7 @@ function endpointLabel(environment: RelayClientEnvironmentRecord): string {
38 function confirmDeregister(environment: RelayClientEnvironmentRecord, onConfirm: () => void) {
39 const title = "Deregister server?";
40 const message = `“${environment.label}” will be removed from this account. T3 Connect access will be revoked, any managed tunnel will be removed, and a host space will become available. Local connections on your devices are not changed.`;
41 - if (process.env.EXPO_OS === "ios") {
42 - Alert.alert(title, message, [
43 - { text: "Cancel", style: "cancel" },
44 - { text: "Deregister", style: "destructive", onPress: onConfirm },
45 - ]);
46 - return;
47 - }
48 - showConfirmDialog({ title, message, confirmText: "Deregister", destructive: true, onConfirm });
41 + Dialog.confirm({ title, message, confirmText: "Deregister", destructive: true, onConfirm });
42 }
43
44 /**
apps/mobile/src/features/development/ComponentCatalogScreen.tsx
+28 -20
@@ -1,9 +1,9 @@
1 import { useNavigation } from "@react-navigation/native";
2 import { useRef, useState } from "react";
3 -import { Alert, Platform, View, type TextInputInstance } from "react-native";
3 +import { View, type TextInputInstance } from "react-native";
4
5 import { AppText, AppTextInput } from "../../components/AppText";
6 -import { AppSheet } from "../../components/AppSheet";
6 +import { Sheet } from "../../components/Sheet";
7 import { Chip } from "../../components/Chip";
8 import { Menu } from "../../components/Menu";
9 import { ListActionRow } from "../../components/ListActionRow";
@@ -22,7 +22,7 @@ import { ScreenHeader } from "../../components/ScreenHeader";
22 import { ScreenScrollView } from "../../components/ScreenScrollView";
23 import { SegmentedControl } from "../../components/SegmentedControl";
24 import { SliderRow } from "../../components/SliderRow";
25 -import { showConfirmDialog } from "../../components/ConfirmDialogHost";
25 +import * as Dialog from "../../components/Dialog";
26 import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
27 import { MOBILE_THEME_IDS } from "../../lib/mobileTheme";
28
@@ -46,19 +46,13 @@ export function ComponentCatalogScreen() {
46 const searchRef = useRef<TextInputInstance>(null);
47 const announceAction = () => setNotice(true);
48 const confirm = () => {
49 - if (Platform.OS === "ios")
50 - Alert.alert("Discard changes?", "This example only changes local catalog state.", [
51 - { text: "Cancel", style: "cancel" },
52 - { text: "Discard", style: "destructive", onPress: () => setText("") },
53 - ]);
54 - else
55 - showConfirmDialog({
56 - title: "Discard changes?",
57 - message: "This example only changes local catalog state.",
58 - confirmText: "Discard",
59 - destructive: true,
60 - onConfirm: () => setText(""),
61 - });
49 + Dialog.confirm({
50 + title: "Discard changes?",
51 + message: "This example only changes local catalog state.",
52 + confirmText: "Discard",
53 + destructive: true,
54 + onConfirm: () => setText(""),
55 + });
56 };
57 return (
58 <View className="flex-1 bg-screen">
@@ -221,6 +215,17 @@ export function ComponentCatalogScreen() {
215 <View className="flex-row flex-wrap gap-2">
216 <Button label="Sheet" onPress={() => setSheet(true)} />
217 <Button label="Dialog" onPress={confirm} />
218 + <Button
219 + label="Prompt"
220 + onPress={() =>
221 + Dialog.prompt({
222 + title: "Rename example",
223 + initialValue: text,
224 + confirmText: "Rename",
225 + onConfirm: setText,
226 + })
227 + }
228 + />
229 <Menu
230 title="Example menu"
231 actions={[
@@ -250,8 +255,11 @@ export function ComponentCatalogScreen() {
255 ) : null}
256 </ScreenScrollView>
257 {sheet ? (
253 - <AppSheet title="Example sheet" onClose={() => setSheet(false)}>
254 - <View className="p-4">
258 + <Sheet title="Example sheet" onClose={() => setSheet(false)}>
259 + <ScreenScrollView
260 + contentInsetAdjustmentBehavior="automatic"
261 + contentContainerClassName="p-4"
262 + >
263 <ListSection>
264 <ListChoiceRow
265 label="Overview"
@@ -264,8 +272,8 @@ export function ComponentCatalogScreen() {
272 onPress={() => setTab("activity")}
273 />
274 </ListSection>
267 - </View>
268 - </AppSheet>
275 + </ScreenScrollView>
276 + </Sheet>
277 ) : null}
278 </View>
279 );
apps/mobile/src/features/home/useThreadListActions.test.ts
+11 -19
@@ -43,8 +43,8 @@ vi.mock("expo-haptics", () => ({
43 impactAsync: async () => {},
44 ImpactFeedbackStyle: { Light: "light" },
45 }));
46 -vi.mock("../../components/ConfirmDialogHost", () => ({
47 - showConfirmDialog: (dialog: { onConfirm: () => void }) => state.dialogs.push(dialog),
46 +vi.mock("../../components/Dialog", () => ({
47 + confirm: (dialog: { onConfirm: () => void }) => state.dialogs.push(dialog),
48 }));
49 vi.mock("../archive/useArchivedThreadSnapshots", () => ({
50 refreshArchivedThreadsForEnvironment: () => {},
@@ -224,8 +224,7 @@ describe("thread list operation permissions", () => {
224 },
225 );
226
227 - it.each(["ios", "android"])("does not show a forbidden %s delete confirmation", (os) => {
228 - vi.stubEnv("EXPO_OS", os);
227 + it("does not show a forbidden delete confirmation", () => {
228 useThreadListActions().confirmDeleteThread(makeThread({ environmentId: otherEnvironmentId }));
229
230 expect(state.dialogs).toEqual([]);
@@ -233,23 +232,16 @@ describe("thread list operation permissions", () => {
232 expect(state.requests).toEqual([]);
233 });
234
236 - it.each(["ios", "android"])(
237 - "rechecks permission after a retained %s delete confirmation",
238 - async (os) => {
239 - vi.stubEnv("EXPO_OS", os);
240 - useThreadListActions().confirmDeleteThread(makeThread());
241 - const confirm =
242 - os === "ios"
243 - ? state.alerts[0]?.buttons?.find((button) => button.text === "Delete")?.onPress
244 - : state.dialogs[0]?.onConfirm;
245 - expect(confirm).toBeTypeOf("function");
246 - state.scopes.get(primaryEnvironmentId)!.clear();
235 + it("rechecks permission after a retained delete confirmation", async () => {
236 + useThreadListActions().confirmDeleteThread(makeThread());
237 + const confirm = state.dialogs[0]?.onConfirm;
238 + expect(confirm).toBeTypeOf("function");
239 + state.scopes.get(primaryEnvironmentId)!.clear();
240
248 - await confirm!();
241 + await confirm!();
242
250 - expect(state.requests).toEqual([]);
251 - },
252 - );
243 + expect(state.requests).toEqual([]);
244 + });
245
246 it("unarchives with only task permission and blocks a later revoked callback", async () => {
247 const actions = useArchivedThreadListActions(() => {});
apps/mobile/src/features/home/useThreadListActions.ts
+4 -27
@@ -5,10 +5,10 @@ import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
5 import * as Cause from "effect/Cause";
6 import * as Haptics from "expo-haptics";
7 import { useCallback, useRef } from "react";
8 -import { Alert, Platform } from "react-native";
8 +import { Alert } from "react-native";
9
10 import { withThreadDismissal } from "./thread-dismissal";
11 -import { showConfirmDialog, showTextInputDialog } from "../../components/ConfirmDialogHost";
11 +import * as Dialog from "../../components/Dialog";
12 import { scopedThreadKey } from "../../lib/scopedEntities";
13 import { refreshArchivedThreadsForEnvironment } from "../archive/useArchivedThreadSnapshots";
14 import { pinOrderKeyBetween } from "@t3tools/client-runtime/state/thread-sort";
@@ -217,20 +217,7 @@ function useConfirmDeleteThread(
217 if (!checkThreadOperationPermission(thread, actionFailureTitle("delete"))) return;
218 const title = "Delete thread?";
219 const message = `“${thread.title}” will be permanently deleted, including its terminal history.`;
220 - if (process.env.EXPO_OS === "ios") {
221 - Alert.alert(title, message, [
222 - { text: "Cancel", style: "cancel" },
223 - {
224 - text: "Delete",
225 - style: "destructive",
226 - onPress: () => {
227 - void executeAction("delete", thread);
228 - },
229 - },
230 - ]);
231 - return;
232 - }
233 - showConfirmDialog({
220 + Dialog.confirm({
221 title,
222 message,
223 confirmText: "Delete",
@@ -560,17 +547,7 @@ export function useThreadListActions(): {
547 });
548 };
549
563 - if (Platform.OS === "ios") {
564 - Alert.prompt(
565 - "Rename thread",
566 - undefined,
567 - (title) => commit(title ?? ""),
568 - "plain-text",
569 - thread.title,
570 - );
571 - return;
572 - }
573 - showTextInputDialog({
550 + Dialog.prompt({
551 title: "Rename thread",
552 initialValue: thread.title,
553 confirmText: "Rename",
apps/mobile/src/features/settings/SettingsClientStorageRouteScreen.tsx
+19 -26
@@ -1,10 +1,11 @@
1 +import * as Dialog from "../../components/Dialog";
2 import { AppActivityIndicator } from "../../components/AppActivityIndicator";
3 import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
4 import { useAtomSet, useAtomValue } from "@effect/atom-react";
5 import { type EnvironmentMachineKind, resolveEnvironmentMachineKind } from "@t3tools/contracts";
6 import { AsyncResult } from "effect/reactivity";
7 import { useMemo } from "react";
7 -import { Alert, Pressable, View } from "react-native";
8 +import { Pressable, View } from "react-native";
9 import { useSafeAreaInsets } from "react-native-safe-area-context";
10
11 import { AppText as Text } from "../../components/AppText";
@@ -44,34 +45,26 @@ export function SettingsClientStorageRouteScreen() {
45 const label =
46 savedConnectionsById[environment.environmentId]?.environmentLabel ??
47 environment.environmentId;
47 - Alert.alert(
48 - `Clear cache for ${label}?`,
49 - "This removes offline threads, server metadata, and cached branches for this environment. The saved connection and credentials stay intact.",
50 - [
51 - { text: "Cancel", style: "cancel" },
52 - {
53 - text: "Clear Cache",
54 - style: "destructive",
55 - onPress: () =>
56 - clearCache({ type: "environment", environmentId: environment.environmentId }),
57 - },
58 - ],
59 - );
48 + Dialog.confirm({
49 + title: `Clear cache for ${label}?`,
50 + message:
51 + "This removes offline threads, server metadata, and cached branches for this environment. The saved connection and credentials stay intact.",
52 + confirmText: "Clear Cache",
53 + destructive: true,
54 + onConfirm: () =>
55 + clearCache({ type: "environment", environmentId: environment.environmentId }),
56 + });
57 };
58
59 const confirmClearAll = () => {
63 - Alert.alert(
64 - "Clear all client caches?",
65 - "This removes offline data for every environment. Connections, credentials, account data, and app preferences stay intact.",
66 - [
67 - { text: "Cancel", style: "cancel" },
68 - {
69 - text: "Clear All Caches",
70 - style: "destructive",
71 - onPress: () => clearCache({ type: "all" }),
72 - },
73 - ],
74 - );
60 + Dialog.confirm({
61 + title: "Clear all client caches?",
62 + message:
63 + "This removes offline data for every environment. Connections, credentials, account data, and app preferences stay intact.",
64 + confirmText: "Clear All Caches",
65 + destructive: true,
66 + onConfirm: () => clearCache({ type: "all" }),
67 + });
68 };
69
70 return (
apps/mobile/src/features/terminal/TerminalContextSheet.tsx
+3 -3
@@ -10,7 +10,7 @@ import { Alert, Platform, Pressable, ScrollView, View } from "react-native";
10 import { useSafeAreaInsets } from "react-native-safe-area-context";
11 import { REVIEW_MONO_FONT_FAMILY } from "../review/reviewDiffRendering";
12 import { AppText as Text } from "../../components/AppText";
13 -import { AppSheet } from "../../components/AppSheet";
13 +import { Sheet } from "../../components/Sheet";
14 import { Button } from "../../components/Button";
15 import { uuidv4 } from "../../lib/uuid";
16 import { insertComposerDraftContext } from "../../state/use-composer-drafts";
@@ -56,7 +56,7 @@ export function TerminalContextSheet(props: {
56 props.onAttach();
57 };
58 return (
59 - <AppSheet title="Terminal output" onClose={props.onClose}>
59 + <Sheet title="Terminal output" onClose={props.onClose}>
60 <ScrollView
61 className="flex-1"
62 contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
@@ -120,6 +120,6 @@ export function TerminalContextSheet(props: {
120 onPress={attach}
121 />
122 </View>
123 - </AppSheet>
123 + </Sheet>
124 );
125 }
apps/mobile/src/features/threads/worktree-setup-sheet.tsx
+3 -3
@@ -1,5 +1,5 @@
1 import type { ReactElement } from "react";
2 -import { AppSheet } from "../../components/AppSheet";
2 +import { Sheet } from "../../components/Sheet";
3
4 export interface WorktreeSetupSheetProps {
5 children: ReactElement;
@@ -9,8 +9,8 @@ export interface WorktreeSetupSheetProps {
9
10 export function WorktreeSetupSheet({ children, onClose }: WorktreeSetupSheetProps) {
11 return (
12 - <AppSheet title="Worktree setup" onClose={onClose}>
12 + <Sheet title="Worktree setup" onClose={onClose}>
13 {children}
14 - </AppSheet>
14 + </Sheet>
15 );
16 }