TypeScript
refactor(mobile): centralize dialog and sheet APIs (#19266)
Julius Marminge8d2e919c15d9
diff --git a/apps/mobile/src/App.tsx b/apps/mobile/src/App.tsxindex 9be57907b35..cccae2de290 100644--- a/apps/mobile/src/App.tsx+++ b/apps/mobile/src/App.tsx@@ -10,7 +10,7 @@ import { createStaticNavigation } from "@react-navigation/native";import { RegistryContext } from "@effect/atom-react";import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet";-import { ConfirmDialogHost } from "./components/ConfirmDialogHost";+import * as Dialog from "./components/Dialog";import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider";@@ -96,7 +96,7 @@ function AppContent() {<IncomingShareProvider><Navigation linking={appLinking} theme={navigationTheme} /></IncomingShareProvider>- <ConfirmDialogHost />+ <Dialog.Host /><ThreadArrangementHost /></NativeLayoutMetricsProvider></GlobalVoiceInputControl>diff --git a/apps/mobile/src/components/AppSheet.tsx b/apps/mobile/src/components/AppSheet.tsxdeleted file mode 100644index ad9bab6e2f5..00000000000--- a/apps/mobile/src/components/AppSheet.tsx+++ /dev/null@@ -1,80 +0,0 @@-import { useId, useState, type ReactNode } from "react";-import { Platform, View } from "react-native";-import { FormSheet, Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";-import { useResolveClassNames, withUniwind } from "uniwind";--import { AndroidSheetHeader } from "./AndroidScreenHeader";-import { nativeHeaderScrollEdgeEffects } from "../native/StackHeader";--const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);-const NativeScreen = withUniwind(Screen);-const NativeHeader = withUniwind(ScreenStackHeaderConfig, {- color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },- titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },-});--/** Native presentation for local context whose owner supplies its dismissal callback. */-export function AppSheet(props: {- readonly title: string;- readonly children: ReactNode;- readonly onClose: () => void;-}) {- const containerStyle = useResolveClassNames("bg-sheet");- const screenId = useId();- const [isOpen, setIsOpen] = useState(true);- const close = () => setIsOpen(false);-- return (- <FormSheet- isOpen={isOpen}- detents={[0.5, 0.9]}- prefersGrabberVisible- nativeContainerStyle={containerStyle}- onDismiss={props.onClose}- onNativeDismiss={props.onClose}- >- <View collapsable={false} className="flex-1 bg-sheet">- {Platform.OS === "ios" ? (- <ScreenStack style={{ flex: 1 }}>- <NativeScreen- activityState={2}- enabled- isNativeStack- screenId={`app-sheet-${screenId}`}- scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}- className="flex-1 bg-sheet"- >- {props.children}- <NativeHeader- backgroundColor="rgba(0,0,0,0)"- tintColorClassName="accent-foreground"- hideBackButton- hideShadow={false}- title={props.title}- titleColorClassName="accent-foreground"- titleFontSize={18}- titleFontWeight="800"- translucent- headerRightBarButtonItems={[- {- type: "button",- title: "Done",- variant: "done",- accessibilityLabel: `Close ${props.title}`,- identifier: `app-sheet-done-${screenId}`,- onPress: close,- },- ]}- />- </NativeScreen>- </ScreenStack>- ) : (- <>- <AndroidSheetHeader title={props.title} onBack={close} />- {props.children}- </>- )}- </View>- </FormSheet>- );-}diff --git a/apps/mobile/src/components/ComposerContextSheet.tsx b/apps/mobile/src/components/ComposerContextSheet.tsxindex 00bf52e4a1c..4cb92829285 100644--- a/apps/mobile/src/components/ComposerContextSheet.tsx+++ b/apps/mobile/src/components/ComposerContextSheet.tsx@@ -24,7 +24,7 @@ import { FilePreviewModal } from "./FilePreviewModal";import { VideoPreviewModal } from "./VideoPreviewModal";import { ComposerContextAttachment } from "./ComposerContextAttachment";import { AppText as Text } from "./AppText";-import { AppSheet } from "./AppSheet";+import { Sheet } from "./Sheet";import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";import { getMobileTerminalTheme } from "../features/terminal/terminalTheme";@@ -183,7 +183,7 @@ export function ComposerContextSheet(props: {: undefined;const terminal = record?.kind === "terminal" && !("payload" in record) ? record : null;return (- <AppSheet title={terminal?.terminalLabel ?? props.label} onClose={props.onClose}>+ <Sheet title={terminal?.terminalLabel ?? props.label} onClose={props.onClose}><ScrollViewclassName="flex-1"contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}@@ -390,6 +390,6 @@ export function ComposerContextSheet(props: {</Pressable>) : null}</ScrollView>- </AppSheet>+ </Sheet>);}diff --git a/apps/mobile/src/components/ConfirmDialogHost.tsx b/apps/mobile/src/components/ConfirmDialogHost.tsxdeleted file mode 100644index 67e9d465c57..00000000000--- a/apps/mobile/src/components/ConfirmDialogHost.tsx+++ /dev/null@@ -1,152 +0,0 @@-import { useCallback, useEffect, useState } from "react";-import { Platform, Modal, Pressable, TextInput, View } from "react-native";--import { cn } from "../lib/cn";-import { AppText } from "./AppText";-import { MaterialConfirmDialog } from "./MaterialConfirmDialog";-import type { ConfirmDialogRequest, TextInputDialogRequest } from "./ConfirmDialog.types";--export type { ConfirmDialogRequest, TextInputDialogRequest } from "./ConfirmDialog.types";--type DialogRequest =- | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }- | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };--let presentRequest: ((request: DialogRequest) => void) | null = null;--/**- * Imperative confirm dialog, Alert.alert-shaped. Native iOS alerts already- * match the app (and support per-button destructive red), so this is for- * Android, where the native dialog can only theme all confirm buttons at- * once. Requires ConfirmDialogHost to be mounted at the app root.- */-export function showConfirmDialog(request: ConfirmDialogRequest): void {- presentRequest?.({ kind: "confirm", request });-}--export function showTextInputDialog(request: TextInputDialogRequest): void {- presentRequest?.({ kind: "text-input", request });-}--/**- * Android-style alert dialog matching the native one themed by- * withAndroidModernAlertDialog — left-aligned text, right-aligned text- * buttons — with what the native theme can't do: a per-dialog destructive- * button color and a dimmer message than the title.- */-export function ConfirmDialogHost() {- const [presented, setPresented] = useState<DialogRequest | null>(null);- const [inputValue, setInputValue] = useState("");- useEffect(() => {- presentRequest = (request) => {- setInputValue(request.kind === "text-input" ? request.request.initialValue : "");- setPresented(request);- };- return () => {- presentRequest = null;- };- }, []);-- const handleCancel = useCallback(() => {- presented?.request.onCancel?.();- setPresented(null);- }, [presented]);-- const handleConfirm = useCallback(- (nativeInputValue?: string) => {- if (presented?.kind === "confirm") {- presented.request.onConfirm();- } else if (presented?.kind === "text-input") {- presented.request.onConfirm(nativeInputValue ?? inputValue);- }- setPresented(null);- },- [inputValue, presented],- );-- const confirmDisabled = presented?.kind === "text-input" && inputValue.trim().length === 0;-- if (Platform.OS === "android")- return presented ? (- <MaterialConfirmDialog- key={`${presented.kind}:${presented.request.title}:${presented.kind === "text-input" ? presented.request.initialValue : ""}`}- request={presented.request}- inputInitialValue={- presented.kind === "text-input" ? presented.request.initialValue : undefined- }- onInputChange={setInputValue}- confirmDisabled={confirmDisabled}- onCancel={handleCancel}- onConfirm={handleConfirm}- />- ) : null;-- return (- <Modal- visible={presented !== null}- transparent- animationType="fade"- statusBarTranslucent- navigationBarTranslucent- onRequestClose={handleCancel}- >- {presented === null ? null : (- <View className="flex-1 items-center justify-center bg-backdrop px-8">- <View className="w-full rounded-[24px] bg-card px-6 pb-4 pt-5">- <AppText className="text-lg font-t3-medium">{presented.request.title}</AppText>- {presented.kind === "confirm" && presented.request.message !== undefined ? (- <AppText className="mt-2 text-sm text-foreground-secondary">- {presented.request.message}- </AppText>- ) : null}- {presented.kind === "text-input" ? (- <TextInput- accessibilityLabel={presented.request.title}- autoFocus- className="mt-4 rounded-xl border border-border bg-screen px-3 py-2.5 text-base text-foreground"- onChangeText={setInputValue}- onSubmitEditing={confirmDisabled ? undefined : () => handleConfirm()}- returnKeyType="done"- selectTextOnFocus- value={inputValue}- />- ) : null}- <View className="mt-5 flex-row justify-end gap-1">- <View className="overflow-hidden rounded-full">- <Pressable- accessibilityRole="button"- className="min-h-10 items-center justify-center px-4 active:bg-subtle"- onPress={handleCancel}- >- <AppText className="text-base font-t3-medium">- {presented.request.cancelText ?? "Cancel"}- </AppText>- </Pressable>- </View>- <View className="overflow-hidden rounded-full">- <Pressable- accessibilityRole="button"- disabled={confirmDisabled}- className="min-h-10 items-center justify-center px-4 active:bg-subtle"- onPress={() => handleConfirm()}- >- <AppText- className={cn(- "text-base font-t3-medium",- presented.kind === "confirm" &&- presented.request.destructive &&- "text-danger-foreground",- confirmDisabled && "text-foreground-tertiary",- )}- >- {presented.request.confirmText}- </AppText>- </Pressable>- </View>- </View>- </View>- </View>- )}- </Modal>- );-}diff --git a/apps/mobile/src/components/MaterialConfirmDialog.android.tsx b/apps/mobile/src/components/Dialog.android.tsxsimilarity index 57%rename from apps/mobile/src/components/MaterialConfirmDialog.android.tsxrename to apps/mobile/src/components/Dialog.android.tsxindex dbd47797d8a..fae9f174592 100644--- a/apps/mobile/src/components/MaterialConfirmDialog.android.tsx+++ b/apps/mobile/src/components/Dialog.android.tsx@@ -9,9 +9,75 @@ import {import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";-import type { MaterialConfirmDialogProps } from "./MaterialConfirmDialog";-export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {+import { useCallback, useEffect, useRef, useState } from "react";+import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";++export type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";++type DialogRequest =+ | { readonly kind: "confirm"; readonly request: ConfirmDialogRequest }+ | { readonly kind: "text-input"; readonly request: TextInputDialogRequest };++let presentRequest: ((request: DialogRequest) => void) | null = null;++export function confirm(request: ConfirmDialogRequest): void {+ presentRequest?.({ kind: "confirm", request });+}++export function prompt(request: TextInputDialogRequest): void {+ presentRequest?.({ kind: "text-input", request });+}++/** Android presenter for Dialog.confirm and Dialog.prompt; mounted once at the app root. */+export function Host() {+ const [presented, setPresented] = useState<(DialogRequest & { readonly id: number }) | null>(+ null,+ );+ const [inputValue, setInputValue] = useState("");+ const nextPresentationId = useRef(0);+ useEffect(() => {+ presentRequest = (request) => {+ setInputValue(request.kind === "text-input" ? request.request.initialValue : "");+ setPresented({ ...request, id: ++nextPresentationId.current });+ };+ return () => {+ presentRequest = null;+ };+ }, []);++ const handleCancel = useCallback(() => {+ setPresented(null);+ presented?.request.onCancel?.();+ }, [presented]);++ const handleConfirm = useCallback(+ (nativeInputValue?: string) => {+ setPresented(null);+ if (presented?.kind === "confirm") {+ presented.request.onConfirm();+ } else if (presented?.kind === "text-input") {+ presented.request.onConfirm(nativeInputValue ?? inputValue);+ }+ },+ [inputValue, presented],+ );++ return presented ? (+ <DialogPresentation+ key={presented.id}+ request={presented.request}+ inputInitialValue={+ presented.kind === "text-input" ? presented.request.initialValue : undefined+ }+ onInputChange={setInputValue}+ onCancel={handleCancel}+ onConfirm={handleConfirm}+ />+ ) : null;+}++function DialogPresentation(props: DialogPresentationProps) {const { themeVariables: colors } = useAppearancePreferences();const titleTypography = useScaledTextRole("title");const bodyTypography = useScaledTextRole("footnote");@@ -19,9 +85,7 @@ export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {const inputState = useNativeState(props.inputInitialValue ?? "");const inputSelection = useNativeState({ start: 0, end: props.inputInitialValue?.length ?? 0 });const confirm = () => {- if (props.confirmDisabled) return;const value = props.inputInitialValue === undefined ? undefined : inputState.get();- if (value !== undefined && !value.trim()) return;props.onConfirm(value);};return (@@ -80,7 +144,6 @@ export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {<AlertDialog.ConfirmButton><TextButtononClick={confirm}- enabled={!props.confirmDisabled}colors={{contentColor:colors[@@ -95,3 +158,14 @@ export function MaterialConfirmDialog(props: MaterialConfirmDialogProps) {</NativeThemeHost>);}++interface DialogPresentationProps {+ readonly request: Pick<+ ConfirmDialogRequest,+ "title" | "message" | "cancelText" | "confirmText" | "destructive"+ >;+ readonly inputInitialValue?: string;+ readonly onInputChange?: (value: string) => void;+ readonly onCancel: () => void;+ readonly onConfirm: (inputValue?: string) => void;+}diff --git a/apps/mobile/src/components/Dialog.ts b/apps/mobile/src/components/Dialog.tsnew file mode 100644index 00000000000..e7706322141--- /dev/null+++ b/apps/mobile/src/components/Dialog.ts@@ -0,0 +1,33 @@+import { Alert } from "react-native";+import type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";++export type { ConfirmDialogRequest, TextInputDialogRequest } from "./Dialog.types";++export function confirm(request: ConfirmDialogRequest): void {+ Alert.alert(request.title, request.message, [+ { text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },+ {+ text: request.confirmText,+ style: request.destructive ? "destructive" : "default",+ onPress: request.onConfirm,+ },+ ]);+}++export function prompt(request: TextInputDialogRequest): void {+ Alert.prompt(+ request.title,+ undefined,+ [+ { text: request.cancelText ?? "Cancel", style: "cancel", onPress: request.onCancel },+ { text: request.confirmText, onPress: (value) => request.onConfirm(value ?? "") },+ ],+ "plain-text",+ request.initialValue,+ );+}++/** iOS alerts are presented directly by React Native. */+export function Host() {+ return null;+}diff --git a/apps/mobile/src/components/ConfirmDialog.types.ts b/apps/mobile/src/components/Dialog.types.tssimilarity index 100%rename from apps/mobile/src/components/ConfirmDialog.types.tsrename to apps/mobile/src/components/Dialog.types.tsdiff --git a/apps/mobile/src/components/MaterialConfirmDialog.tsx b/apps/mobile/src/components/MaterialConfirmDialog.tsxdeleted file mode 100644index 7154c7d716d..00000000000--- a/apps/mobile/src/components/MaterialConfirmDialog.tsx+++ /dev/null@@ -1,17 +0,0 @@-import type { ConfirmDialogRequest } from "./ConfirmDialog.types";--export interface MaterialConfirmDialogProps {- readonly request: Pick<- ConfirmDialogRequest,- "title" | "message" | "cancelText" | "confirmText" | "destructive"- >;- readonly inputInitialValue?: string;- readonly onInputChange?: (value: string) => void;- readonly confirmDisabled?: boolean;- readonly onCancel: () => void;- readonly onConfirm: (inputValue?: string) => void;-}--export function MaterialConfirmDialog(_props: MaterialConfirmDialogProps) {- return null;-}diff --git a/apps/mobile/src/components/Sheet.android.tsx b/apps/mobile/src/components/Sheet.android.tsxnew file mode 100644index 00000000000..52cad92e0ab--- /dev/null+++ b/apps/mobile/src/components/Sheet.android.tsx@@ -0,0 +1,27 @@+import { useState } from "react";+import { View } from "react-native";+import { FormSheet } from "react-native-screens";+import { useResolveClassNames } from "uniwind";+import { AndroidSheetHeader } from "./AndroidScreenHeader";+import type { SheetProps } from "./Sheet.types";+export type { SheetProps } from "./Sheet.types";++export function Sheet(props: SheetProps) {+ const containerStyle = useResolveClassNames("bg-sheet");+ const [isOpen, setIsOpen] = useState(true);+ return (+ <FormSheet+ isOpen={isOpen}+ detents={[0.5, 0.9]}+ prefersGrabberVisible+ nativeContainerStyle={containerStyle}+ onDismiss={props.onClose}+ onNativeDismiss={props.onClose}+ >+ <View collapsable={false} className="flex-1 bg-sheet">+ <AndroidSheetHeader title={props.title} onBack={() => setIsOpen(false)} />+ {props.children}+ </View>+ </FormSheet>+ );+}diff --git a/apps/mobile/src/components/Sheet.tsx b/apps/mobile/src/components/Sheet.tsxnew file mode 100644index 00000000000..68be8e3d7fe--- /dev/null+++ b/apps/mobile/src/components/Sheet.tsx@@ -0,0 +1,71 @@+import { useId, useState } from "react";+import { Platform, View } from "react-native";+import { FormSheet, Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";+import { useResolveClassNames, withUniwind } from "uniwind";++import { nativeHeaderScrollEdgeEffects } from "../native/StackHeader";++const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);+const NativeScreen = withUniwind(Screen);+const NativeHeader = withUniwind(ScreenStackHeaderConfig, {+ color: { fromClassName: "tintColorClassName", styleProperty: "accentColor" },+ titleColor: { fromClassName: "titleColorClassName", styleProperty: "accentColor" },+});++export type { SheetProps } from "./Sheet.types";+import type { SheetProps } from "./Sheet.types";++/** Native presentation. Scrollable children use automatic insets beneath the iOS header. */+export function Sheet(props: SheetProps) {+ const containerStyle = useResolveClassNames("bg-sheet");+ const screenId = useId();+ const [isOpen, setIsOpen] = useState(true);+ const close = () => setIsOpen(false);++ return (+ <FormSheet+ isOpen={isOpen}+ detents={[0.5, 0.9]}+ prefersGrabberVisible+ nativeContainerStyle={containerStyle}+ onDismiss={props.onClose}+ onNativeDismiss={props.onClose}+ >+ <View collapsable={false} className="flex-1 bg-sheet">+ <ScreenStack style={{ flex: 1 }}>+ <NativeScreen+ activityState={2}+ enabled+ isNativeStack+ screenId={`app-sheet-${screenId}`}+ scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}+ className="flex-1 bg-sheet"+ >+ {props.children}+ <NativeHeader+ backgroundColor="rgba(0,0,0,0)"+ tintColorClassName="accent-foreground"+ hideBackButton+ hideShadow={false}+ title={props.title}+ titleColorClassName="accent-foreground"+ titleFontSize={18}+ titleFontWeight="800"+ translucent+ headerRightBarButtonItems={[+ {+ type: "button",+ title: "Done",+ variant: "done",+ accessibilityLabel: `Close ${props.title}`,+ identifier: `app-sheet-done-${screenId}`,+ onPress: close,+ },+ ]}+ />+ </NativeScreen>+ </ScreenStack>+ </View>+ </FormSheet>+ );+}diff --git a/apps/mobile/src/components/Sheet.types.ts b/apps/mobile/src/components/Sheet.types.tsnew file mode 100644index 00000000000..8c0af06edb3--- /dev/null+++ b/apps/mobile/src/components/Sheet.types.ts@@ -0,0 +1,7 @@+import type { ReactNode } from "react";++export interface SheetProps {+ readonly title: string;+ readonly children: ReactNode;+ readonly onClose: () => void;+}diff --git a/apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx b/apps/mobile/src/features/cloud/T3ConnectProfilePage.tsxindex 53073889848..73e9f40eb19 100644--- a/apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx+++ b/apps/mobile/src/features/cloud/T3ConnectProfilePage.tsx@@ -11,7 +11,7 @@ import { Alert, Pressable, RefreshControl, ScrollView, Text, View } from "react-import { AppActivityIndicator } from "../../components/AppActivityIndicator";import { SymbolView } from "../../components/AppSymbol";-import { showConfirmDialog } from "../../components/ConfirmDialogHost";+import * as Dialog from "../../components/Dialog";import { Menu } from "../../components/Menu";import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";import { useAtomCommand } from "../../state/use-atom-command";@@ -38,14 +38,7 @@ function endpointLabel(environment: RelayClientEnvironmentRecord): string {function confirmDeregister(environment: RelayClientEnvironmentRecord, onConfirm: () => void) {const title = "Deregister server?";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.`;- if (process.env.EXPO_OS === "ios") {- Alert.alert(title, message, [- { text: "Cancel", style: "cancel" },- { text: "Deregister", style: "destructive", onPress: onConfirm },- ]);- return;- }- showConfirmDialog({ title, message, confirmText: "Deregister", destructive: true, onConfirm });+ Dialog.confirm({ title, message, confirmText: "Deregister", destructive: true, onConfirm });}/**diff --git a/apps/mobile/src/features/development/ComponentCatalogScreen.tsx b/apps/mobile/src/features/development/ComponentCatalogScreen.tsxindex 3e7af4b2cc5..7fdd727a74b 100644--- a/apps/mobile/src/features/development/ComponentCatalogScreen.tsx+++ b/apps/mobile/src/features/development/ComponentCatalogScreen.tsx@@ -1,9 +1,9 @@import { useNavigation } from "@react-navigation/native";import { useRef, useState } from "react";-import { Alert, Platform, View, type TextInputInstance } from "react-native";+import { View, type TextInputInstance } from "react-native";import { AppText, AppTextInput } from "../../components/AppText";-import { AppSheet } from "../../components/AppSheet";+import { Sheet } from "../../components/Sheet";import { Chip } from "../../components/Chip";import { Menu } from "../../components/Menu";import { ListActionRow } from "../../components/ListActionRow";@@ -22,7 +22,7 @@ import { ScreenHeader } from "../../components/ScreenHeader";import { ScreenScrollView } from "../../components/ScreenScrollView";import { SegmentedControl } from "../../components/SegmentedControl";import { SliderRow } from "../../components/SliderRow";-import { showConfirmDialog } from "../../components/ConfirmDialogHost";+import * as Dialog from "../../components/Dialog";import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";import { MOBILE_THEME_IDS } from "../../lib/mobileTheme";@@ -46,19 +46,13 @@ export function ComponentCatalogScreen() {const searchRef = useRef<TextInputInstance>(null);const announceAction = () => setNotice(true);const confirm = () => {- if (Platform.OS === "ios")- Alert.alert("Discard changes?", "This example only changes local catalog state.", [- { text: "Cancel", style: "cancel" },- { text: "Discard", style: "destructive", onPress: () => setText("") },- ]);- else- showConfirmDialog({- title: "Discard changes?",- message: "This example only changes local catalog state.",- confirmText: "Discard",- destructive: true,- onConfirm: () => setText(""),- });+ Dialog.confirm({+ title: "Discard changes?",+ message: "This example only changes local catalog state.",+ confirmText: "Discard",+ destructive: true,+ onConfirm: () => setText(""),+ });};return (<View className="flex-1 bg-screen">@@ -221,6 +215,17 @@ export function ComponentCatalogScreen() {<View className="flex-row flex-wrap gap-2"><Button label="Sheet" onPress={() => setSheet(true)} /><Button label="Dialog" onPress={confirm} />+ <Button+ label="Prompt"+ onPress={() =>+ Dialog.prompt({+ title: "Rename example",+ initialValue: text,+ confirmText: "Rename",+ onConfirm: setText,+ })+ }+ /><Menutitle="Example menu"actions={[@@ -250,8 +255,11 @@ export function ComponentCatalogScreen() {) : null}</ScreenScrollView>{sheet ? (- <AppSheet title="Example sheet" onClose={() => setSheet(false)}>- <View className="p-4">+ <Sheet title="Example sheet" onClose={() => setSheet(false)}>+ <ScreenScrollView+ contentInsetAdjustmentBehavior="automatic"+ contentContainerClassName="p-4"+ ><ListSection><ListChoiceRowlabel="Overview"@@ -264,8 +272,8 @@ export function ComponentCatalogScreen() {onPress={() => setTab("activity")}/></ListSection>- </View>- </AppSheet>+ </ScreenScrollView>+ </Sheet>) : null}</View>);diff --git a/apps/mobile/src/features/home/useThreadListActions.test.ts b/apps/mobile/src/features/home/useThreadListActions.test.tsindex 4fffe5f36c1..b702d467efd 100644--- a/apps/mobile/src/features/home/useThreadListActions.test.ts+++ b/apps/mobile/src/features/home/useThreadListActions.test.ts@@ -43,8 +43,8 @@ vi.mock("expo-haptics", () => ({impactAsync: async () => {},ImpactFeedbackStyle: { Light: "light" },}));-vi.mock("../../components/ConfirmDialogHost", () => ({- showConfirmDialog: (dialog: { onConfirm: () => void }) => state.dialogs.push(dialog),+vi.mock("../../components/Dialog", () => ({+ confirm: (dialog: { onConfirm: () => void }) => state.dialogs.push(dialog),}));vi.mock("../archive/useArchivedThreadSnapshots", () => ({refreshArchivedThreadsForEnvironment: () => {},@@ -224,8 +224,7 @@ describe("thread list operation permissions", () => {},);- it.each(["ios", "android"])("does not show a forbidden %s delete confirmation", (os) => {- vi.stubEnv("EXPO_OS", os);+ it("does not show a forbidden delete confirmation", () => {useThreadListActions().confirmDeleteThread(makeThread({ environmentId: otherEnvironmentId }));expect(state.dialogs).toEqual([]);@@ -233,23 +232,16 @@ describe("thread list operation permissions", () => {expect(state.requests).toEqual([]);});- it.each(["ios", "android"])(- "rechecks permission after a retained %s delete confirmation",- async (os) => {- vi.stubEnv("EXPO_OS", os);- useThreadListActions().confirmDeleteThread(makeThread());- const confirm =- os === "ios"- ? state.alerts[0]?.buttons?.find((button) => button.text === "Delete")?.onPress- : state.dialogs[0]?.onConfirm;- expect(confirm).toBeTypeOf("function");- state.scopes.get(primaryEnvironmentId)!.clear();+ it("rechecks permission after a retained delete confirmation", async () => {+ useThreadListActions().confirmDeleteThread(makeThread());+ const confirm = state.dialogs[0]?.onConfirm;+ expect(confirm).toBeTypeOf("function");+ state.scopes.get(primaryEnvironmentId)!.clear();- await confirm!();+ await confirm!();- expect(state.requests).toEqual([]);- },- );+ expect(state.requests).toEqual([]);+ });it("unarchives with only task permission and blocks a later revoked callback", async () => {const actions = useArchivedThreadListActions(() => {});diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.tsindex 8e5db2faf99..889484418a4 100644--- a/apps/mobile/src/features/home/useThreadListActions.ts+++ b/apps/mobile/src/features/home/useThreadListActions.ts@@ -5,10 +5,10 @@ import { AuthOrchestrationOperateScope } from "@t3tools/contracts";import * as Cause from "effect/Cause";import * as Haptics from "expo-haptics";import { useCallback, useRef } from "react";-import { Alert, Platform } from "react-native";+import { Alert } from "react-native";import { withThreadDismissal } from "./thread-dismissal";-import { showConfirmDialog, showTextInputDialog } from "../../components/ConfirmDialogHost";+import * as Dialog from "../../components/Dialog";import { scopedThreadKey } from "../../lib/scopedEntities";import { refreshArchivedThreadsForEnvironment } from "../archive/useArchivedThreadSnapshots";import { pinOrderKeyBetween } from "@t3tools/client-runtime/state/thread-sort";@@ -217,20 +217,7 @@ function useConfirmDeleteThread(if (!checkThreadOperationPermission(thread, actionFailureTitle("delete"))) return;const title = "Delete thread?";const message = `“${thread.title}” will be permanently deleted, including its terminal history.`;- if (process.env.EXPO_OS === "ios") {- Alert.alert(title, message, [- { text: "Cancel", style: "cancel" },- {- text: "Delete",- style: "destructive",- onPress: () => {- void executeAction("delete", thread);- },- },- ]);- return;- }- showConfirmDialog({+ Dialog.confirm({title,message,confirmText: "Delete",@@ -560,17 +547,7 @@ export function useThreadListActions(): {});};- if (Platform.OS === "ios") {- Alert.prompt(- "Rename thread",- undefined,- (title) => commit(title ?? ""),- "plain-text",- thread.title,- );- return;- }- showTextInputDialog({+ Dialog.prompt({title: "Rename thread",initialValue: thread.title,confirmText: "Rename",diff --git a/apps/mobile/src/features/settings/SettingsClientStorageRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsClientStorageRouteScreen.tsxindex 9533e10d43b..bd0a3b110c2 100644--- a/apps/mobile/src/features/settings/SettingsClientStorageRouteScreen.tsx+++ b/apps/mobile/src/features/settings/SettingsClientStorageRouteScreen.tsx@@ -1,10 +1,11 @@+import * as Dialog from "../../components/Dialog";import { AppActivityIndicator } from "../../components/AppActivityIndicator";import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";import { useAtomSet, useAtomValue } from "@effect/atom-react";import { type EnvironmentMachineKind, resolveEnvironmentMachineKind } from "@t3tools/contracts";import { AsyncResult } from "effect/reactivity";import { useMemo } from "react";-import { Alert, Pressable, View } from "react-native";+import { Pressable, View } from "react-native";import { useSafeAreaInsets } from "react-native-safe-area-context";import { AppText as Text } from "../../components/AppText";@@ -44,34 +45,26 @@ export function SettingsClientStorageRouteScreen() {const label =savedConnectionsById[environment.environmentId]?.environmentLabel ??environment.environmentId;- Alert.alert(- `Clear cache for ${label}?`,- "This removes offline threads, server metadata, and cached branches for this environment. The saved connection and credentials stay intact.",- [- { text: "Cancel", style: "cancel" },- {- text: "Clear Cache",- style: "destructive",- onPress: () =>- clearCache({ type: "environment", environmentId: environment.environmentId }),- },- ],- );+ Dialog.confirm({+ title: `Clear cache for ${label}?`,+ message:+ "This removes offline threads, server metadata, and cached branches for this environment. The saved connection and credentials stay intact.",+ confirmText: "Clear Cache",+ destructive: true,+ onConfirm: () =>+ clearCache({ type: "environment", environmentId: environment.environmentId }),+ });};const confirmClearAll = () => {- Alert.alert(- "Clear all client caches?",- "This removes offline data for every environment. Connections, credentials, account data, and app preferences stay intact.",- [- { text: "Cancel", style: "cancel" },- {- text: "Clear All Caches",- style: "destructive",- onPress: () => clearCache({ type: "all" }),- },- ],- );+ Dialog.confirm({+ title: "Clear all client caches?",+ message:+ "This removes offline data for every environment. Connections, credentials, account data, and app preferences stay intact.",+ confirmText: "Clear All Caches",+ destructive: true,+ onConfirm: () => clearCache({ type: "all" }),+ });};return (diff --git a/apps/mobile/src/features/terminal/TerminalContextSheet.tsx b/apps/mobile/src/features/terminal/TerminalContextSheet.tsxindex 9798bf231dc..159ea8d9f05 100644--- a/apps/mobile/src/features/terminal/TerminalContextSheet.tsx+++ b/apps/mobile/src/features/terminal/TerminalContextSheet.tsx@@ -10,7 +10,7 @@ import { Alert, Platform, Pressable, ScrollView, View } from "react-native";import { useSafeAreaInsets } from "react-native-safe-area-context";import { REVIEW_MONO_FONT_FAMILY } from "../review/reviewDiffRendering";import { AppText as Text } from "../../components/AppText";-import { AppSheet } from "../../components/AppSheet";+import { Sheet } from "../../components/Sheet";import { Button } from "../../components/Button";import { uuidv4 } from "../../lib/uuid";import { insertComposerDraftContext } from "../../state/use-composer-drafts";@@ -56,7 +56,7 @@ export function TerminalContextSheet(props: {props.onAttach();};return (- <AppSheet title="Terminal output" onClose={props.onClose}>+ <Sheet title="Terminal output" onClose={props.onClose}><ScrollViewclassName="flex-1"contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}@@ -120,6 +120,6 @@ export function TerminalContextSheet(props: {onPress={attach}/></View>- </AppSheet>+ </Sheet>);}diff --git a/apps/mobile/src/features/threads/worktree-setup-sheet.tsx b/apps/mobile/src/features/threads/worktree-setup-sheet.tsxindex e4ec7eae99d..02bf7210f01 100644--- a/apps/mobile/src/features/threads/worktree-setup-sheet.tsx+++ b/apps/mobile/src/features/threads/worktree-setup-sheet.tsx@@ -1,5 +1,5 @@import type { ReactElement } from "react";-import { AppSheet } from "../../components/AppSheet";+import { Sheet } from "../../components/Sheet";export interface WorktreeSetupSheetProps {children: ReactElement;@@ -9,8 +9,8 @@ export interface WorktreeSetupSheetProps {export function WorktreeSetupSheet({ children, onClose }: WorktreeSetupSheetProps) {return (- <AppSheet title="Worktree setup" onClose={onClose}>+ <Sheet title="Worktree setup" onClose={onClose}>{children}- </AppSheet>+ </Sheet>);}