This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 54).
AlertDialog
A Jetpack Compose AlertDialog component for displaying native alert dialogs.
Android
Expo UI AlertDialog matches the official Jetpack Compose AlertDialog API and displays a modal dialog with a title, message text, and confirm/dismiss buttons.
Installation
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Basic alert dialog
BasicAlertDialogExample.tsx
import { useState } from 'react'; import { Host, AlertDialog, Button } from '@expo/ui/jetpack-compose'; export default function BasicAlertDialogExample() { const [visible, setVisible] = useState(false); return ( <Host matchContents> <Button onPress={() => setVisible(true)}>Show Alert</Button> <AlertDialog visible={visible} title="Confirm Action" text="Are you sure you want to proceed?" confirmButtonText="Confirm" dismissButtonText="Cancel" onConfirmPressed={() => { console.log('Confirmed'); setVisible(false); }} onDismissPressed={() => { console.log('Dismissed'); setVisible(false); }} /> </Host> ); }
API
import { AlertDialog } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<AlertDialogProps>
Renders an AlertDialog component.
Optional • Type:
AlertDialogButtonColorsThe colors for the confirm button.
Optional • Type:
AlertDialogButtonColorsThe colors for the dismiss button.
Optional • Type:
() => voidCallback that is called when the user tries to confirm the dialog.
Optional • Type:
() => voidCallback that is called when the user tries to dismiss the dialog.
Types
| Property | Type | Description |
|---|---|---|
| containerColor(optional) | ColorValue | The background color of the button. |
| contentColor(optional) | ColorValue | The text color of the button. |