Reference version

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/ui

If 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

AlertDialog

Android

Type: React.Element<AlertDialogProps>

Renders an AlertDialog component.

AlertDialogProps

confirmButtonColors

Android
Optional • Type: AlertDialogButtonColors

The colors for the confirm button.

confirmButtonText

Android
Optional • Type: string

The text of the confirm button of the alert dialog.

dismissButtonColors

Android
Optional • Type: AlertDialogButtonColors

The colors for the dismiss button.

dismissButtonText

Android
Optional • Type: string

The text of the dismiss button of the alert dialog.

modifiers

Android
Optional • Type: ExpoModifier[]

Modifiers for the component.

onConfirmPressed

Android
Optional • Type: () => void

Callback that is called when the user tries to confirm the dialog.

onDismissPressed

Android
Optional • Type: () => void

Callback that is called when the user tries to dismiss the dialog.

text

Android
Optional • Type: string

The text of the alert dialog.

title

Android
Optional • Type: string

The title of the alert dialog.

visible

Android
Optional • Type: boolean • Default: false

Whether the alert dialog is visible.

Types

AlertDialogButtonColors

Android
PropertyTypeDescription
containerColor(optional)ColorValue

The background color of the button.

contentColor(optional)ColorValue

The text color of the button.