11import { useCallback , useEffect , useState } from "react" ;
22import { Platform , Modal , Pressable , TextInput , View } from "react-native" ;
3+ import { FullWindowOverlay } from "react-native-screens" ;
34
45import { cn } from "../lib/cn" ;
56import { AppText } from "./AppText" ;
@@ -31,10 +32,11 @@ type DialogRequest =
3132let presentRequest : ( ( request : DialogRequest ) => void ) | null = null ;
3233
3334/**
34- * Imperative confirm dialog, Alert.alert-shaped. Native iOS alerts already
35- * match the app (and support per-button destructive red), so this is for
36- * Android, where the native dialog can only theme all confirm buttons at
37- * once. Requires ConfirmDialogHost to be mounted at the app root.
35+ * Imperative confirm dialog, Alert.alert-shaped. Android uses a themed
36+ * in-tree dialog because the native one cannot color a single destructive
37+ * button. iOS uses a FullWindowOverlay so the confirm stays visible above
38+ * nested form sheets — UIAlertController from the key window does not.
39+ * Requires ConfirmDialogHost to be mounted at the app root.
3840 */
3941export function showConfirmDialog ( request : ConfirmDialogRequest ) : void {
4042 presentRequest ?.( { kind : "confirm" , request } ) ;
@@ -97,6 +99,69 @@ export function ConfirmDialogHost() {
9799 />
98100 ) : null ;
99101
102+ const dialog =
103+ presented === null ? null : (
104+ < View className = "flex-1 items-center justify-center bg-backdrop px-8" >
105+ < View className = "w-full rounded-[24px] bg-card px-6 pb-4 pt-5" >
106+ < AppText className = "text-lg font-t3-medium" > { presented . request . title } </ AppText >
107+ { presented . kind === "confirm" && presented . request . message !== undefined ? (
108+ < AppText className = "mt-2 text-sm text-foreground-secondary" >
109+ { presented . request . message }
110+ </ AppText >
111+ ) : null }
112+ { presented . kind === "text-input" ? (
113+ < TextInput
114+ accessibilityLabel = { presented . request . title }
115+ autoFocus
116+ className = "mt-4 rounded-xl border border-border bg-screen px-3 py-2.5 text-base text-foreground"
117+ onChangeText = { setInputValue }
118+ onSubmitEditing = { confirmDisabled ? undefined : ( ) => handleConfirm ( ) }
119+ returnKeyType = "done"
120+ selectTextOnFocus
121+ value = { inputValue }
122+ />
123+ ) : null }
124+ < View className = "mt-5 flex-row justify-end gap-1" >
125+ < View className = "overflow-hidden rounded-full" >
126+ < Pressable
127+ accessibilityRole = "button"
128+ className = "min-h-10 items-center justify-center px-4 active:bg-subtle"
129+ onPress = { handleCancel }
130+ >
131+ < AppText className = "text-base font-t3-medium" >
132+ { presented . request . cancelText ?? "Cancel" }
133+ </ AppText >
134+ </ Pressable >
135+ </ View >
136+ < View className = "overflow-hidden rounded-full" >
137+ < Pressable
138+ accessibilityRole = "button"
139+ disabled = { confirmDisabled }
140+ className = "min-h-10 items-center justify-center px-4 active:bg-subtle"
141+ onPress = { ( ) => handleConfirm ( ) }
142+ >
143+ < AppText
144+ className = { cn (
145+ "text-base font-t3-medium" ,
146+ presented . kind === "confirm" &&
147+ presented . request . destructive &&
148+ "text-danger-foreground" ,
149+ confirmDisabled && "text-foreground-tertiary" ,
150+ ) }
151+ >
152+ { presented . request . confirmText }
153+ </ AppText >
154+ </ Pressable >
155+ </ View >
156+ </ View >
157+ </ View >
158+ </ View >
159+ ) ;
160+
161+ if ( Platform . OS === "ios" ) {
162+ return dialog === null ? null : < FullWindowOverlay > { dialog } </ FullWindowOverlay > ;
163+ }
164+
100165 return (
101166 < Modal
102167 visible = { presented !== null }
@@ -106,63 +171,7 @@ export function ConfirmDialogHost() {
106171 navigationBarTranslucent
107172 onRequestClose = { handleCancel }
108173 >
109- { presented === null ? null : (
110- < View className = "flex-1 items-center justify-center bg-backdrop px-8" >
111- < View className = "w-full rounded-[24px] bg-card px-6 pb-4 pt-5" >
112- < AppText className = "text-lg font-t3-medium" > { presented . request . title } </ AppText >
113- { presented . kind === "confirm" && presented . request . message !== undefined ? (
114- < AppText className = "mt-2 text-sm text-foreground-secondary" >
115- { presented . request . message }
116- </ AppText >
117- ) : null }
118- { presented . kind === "text-input" ? (
119- < TextInput
120- accessibilityLabel = { presented . request . title }
121- autoFocus
122- className = "mt-4 rounded-xl border border-border bg-screen px-3 py-2.5 text-base text-foreground"
123- onChangeText = { setInputValue }
124- onSubmitEditing = { confirmDisabled ? undefined : ( ) => handleConfirm ( ) }
125- returnKeyType = "done"
126- selectTextOnFocus
127- value = { inputValue }
128- />
129- ) : null }
130- < View className = "mt-5 flex-row justify-end gap-1" >
131- < View className = "overflow-hidden rounded-full" >
132- < Pressable
133- accessibilityRole = "button"
134- className = "min-h-10 items-center justify-center px-4 active:bg-subtle"
135- onPress = { handleCancel }
136- >
137- < AppText className = "text-base font-t3-medium" >
138- { presented . request . cancelText ?? "Cancel" }
139- </ AppText >
140- </ Pressable >
141- </ View >
142- < View className = "overflow-hidden rounded-full" >
143- < Pressable
144- accessibilityRole = "button"
145- disabled = { confirmDisabled }
146- className = "min-h-10 items-center justify-center px-4 active:bg-subtle"
147- onPress = { ( ) => handleConfirm ( ) }
148- >
149- < AppText
150- className = { cn (
151- "text-base font-t3-medium" ,
152- presented . kind === "confirm" &&
153- presented . request . destructive &&
154- "text-danger-foreground" ,
155- confirmDisabled && "text-foreground-tertiary" ,
156- ) }
157- >
158- { presented . request . confirmText }
159- </ AppText >
160- </ Pressable >
161- </ View >
162- </ View >
163- </ View >
164- </ View >
165- ) }
174+ { dialog }
166175 </ Modal >
167176 ) ;
168177}
0 commit comments