Expo UI ConfirmationDialog matches the official SwiftUI confirmationDialog API and presents an action sheet-style dialog with a title, actions, and an optional message.
Use ConfirmationDialog.Trigger to define the visible element and ConfirmationDialog.Actions to provide the dialog buttons.
BasicConfirmationDialogExample.tsx
import{ useState }from'react';import{Host,ConfirmationDialog,Button,}from'@expo/ui/swift-ui';exportdefaultfunctionBasicConfirmationDialogExample(){const[isPresented, setIsPresented]=useState(false);return(<Hoststyle={{ flex:1}}><ConfirmationDialogtitle="Are you sure?"isPresented={isPresented}onIsPresentedChange={setIsPresented}titleVisibility="visible"><ConfirmationDialog.Trigger><Buttonlabel="Show dialog"onPress={()=>setIsPresented(true)}/></ConfirmationDialog.Trigger><ConfirmationDialog.Actions><Buttonlabel="Confirm"onPress={()=>setIsPresented(false)}/><Buttonlabel="Cancel"role="cancel"/></ConfirmationDialog.Actions></ConfirmationDialog></Host>);}
Destructive action confirmation
Use role="destructive" on a Button inside ConfirmationDialog.Actions to style it as a destructive action.
DestructiveConfirmationDialogExample.tsx
import{ useState }from'react';import{Host,ConfirmationDialog,Button,Text,}from'@expo/ui/swift-ui';exportdefaultfunctionDestructiveConfirmationDialogExample(){const[isPresented, setIsPresented]=useState(false);return(<Hoststyle={{ flex:1}}><ConfirmationDialogtitle="Delete Item?"isPresented={isPresented}onIsPresentedChange={setIsPresented}titleVisibility="visible"><ConfirmationDialog.Trigger><Buttonlabel="Delete"role="destructive"onPress={()=>setIsPresented(true)}/></ConfirmationDialog.Trigger><ConfirmationDialog.Actions><Buttonlabel="Delete"role="destructive"onPress={()=>{console.log('Deleted');setIsPresented(false);}}/><Buttonlabel="Cancel"role="cancel"/></ConfirmationDialog.Actions><ConfirmationDialog.Message><Text>This action cannot be undone.</Text></ConfirmationDialog.Message></ConfirmationDialog></Host>);}
With message and multiple actions
Use ConfirmationDialog.Message to display a descriptive message below the title, and include multiple action buttons for different choices.
MultiActionConfirmationDialogExample.tsx
import{ useState }from'react';import{Host,ConfirmationDialog,Button,Text,}from'@expo/ui/swift-ui';exportdefaultfunctionMultiActionConfirmationDialogExample(){const[isPresented, setIsPresented]=useState(false);return(<Hoststyle={{ flex:1}}><ConfirmationDialogtitle="Save Changes?"isPresented={isPresented}onIsPresentedChange={setIsPresented}titleVisibility="visible"><ConfirmationDialog.Trigger><Buttonlabel="Close document"onPress={()=>setIsPresented(true)}/></ConfirmationDialog.Trigger><ConfirmationDialog.Actions><Buttonlabel="Save"onPress={()=>console.log('Saved')}/><Buttonlabel="Discard"role="destructive"onPress={()=>console.log('Discarded')}/><Buttonlabel="Cancel"role="cancel"/></ConfirmationDialog.Actions><ConfirmationDialog.Message><Text>
You have unsaved changes. What would you like to do?
</Text></ConfirmationDialog.Message></ConfirmationDialog></Host>);}
Hidden title
Set titleVisibility="hidden" to hide the dialog title while still showing the actions and message. You should still provide a title for accessibility.
HiddenTitleConfirmationDialogExample.tsx
import{ useState }from'react';import{Host,ConfirmationDialog,Button,Text,}from'@expo/ui/swift-ui';exportdefaultfunctionHiddenTitleConfirmationDialogExample(){const[isPresented, setIsPresented]=useState(false);return(<Hoststyle={{ flex:1}}><ConfirmationDialogtitle="Hidden Title"isPresented={isPresented}onIsPresentedChange={setIsPresented}titleVisibility="hidden"><ConfirmationDialog.Trigger><Buttonlabel="Show dialog"onPress={()=>setIsPresented(true)}/></ConfirmationDialog.Trigger><ConfirmationDialog.Actions><Buttonlabel="OK"onPress={()=>setIsPresented(false)}/><Buttonlabel="Cancel"role="cancel"/></ConfirmationDialog.Actions><ConfirmationDialog.Message><Text>Only the message and actions are visible.</Text></ConfirmationDialog.Message></ConfirmationDialog></Host>);}
The contents of the confirmation dialog.
Should include ConfirmationDialog.Trigger, ConfirmationDialog.Actions, and optionally ConfirmationDialog.Message.
isPresented
iOS
tvOS
Optional • Type: boolean
Whether the confirmation dialog is presented.
onIsPresentedChange
iOS
tvOS
Optional • Type: (isPresented: boolean) => void
A callback that is called when the isPresented state changes.