BasicAlertDialog
A Jetpack Compose BasicAlertDialog component for displaying dialogs with custom content.
Expo UI BasicAlertDialog matches the official Jetpack Compose BasicAlertDialog API and displays a minimal dialog that accepts custom children as its content, giving you full control over the dialog layout.
Installation
- 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 dialog with custom content
import { useState } from 'react'; import { Host, BasicAlertDialog, Button, TextButton, Text, Surface, Column, Spacer, } from '@expo/ui/jetpack-compose'; import { padding, wrapContentWidth, wrapContentHeight, clip, height, align, Shapes, } from '@expo/ui/jetpack-compose/modifiers'; export default function BasicAlertDialogExample() { const [visible, setVisible] = useState(false); return ( <Host matchContents> <Button onClick={() => setVisible(true)}> <Text>Open dialog</Text> </Button> {visible && ( <BasicAlertDialog onDismissRequest={() => setVisible(false)}> <Surface tonalElevation={6} modifiers={[wrapContentWidth(), wrapContentHeight(), clip(Shapes.RoundedCorner(28))]}> <Column modifiers={[padding(16, 16, 16, 16)]}> <Text> This area typically contains the supportive text which presents the details regarding the Dialog's purpose. </Text> <Spacer modifiers={[height(24)]} /> <TextButton onClick={() => setVisible(false)} modifiers={[align('centerEnd')]}> <Text>Confirm</Text> </TextButton> </Column> </Surface> </BasicAlertDialog> )} </Host> ); }
API
import { BasicAlertDialog } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<BasicAlertDialogProps>
A basic alert dialog that provides a blank container for custom content.
Unlike AlertDialog, this component does not have structured title/text/buttons slots.
() => voidCallback that is called when the user tries to dismiss the dialog (e.g. by tapping outside of it or pressing the back button).
Types
Properties for the dialog window, matching DialogProperties in Compose.
| Property | Type | Description |
|---|---|---|
| decorFitsSystemWindows(optional) | boolean | Whether the dialog's decor fits system windows. Default: true |
| dismissOnBackPress(optional) | boolean | Whether the dialog can be dismissed by pressing the back button. Default: true |
| dismissOnClickOutside(optional) | boolean | Whether the dialog can be dismissed by clicking outside of it. Default: true |
| usePlatformDefaultWidth(optional) | boolean | Whether the dialog should use the platform default width. Default: true |