Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

BasicAlertDialog

一个 Jetpack Compose BasicAlertDialog 组件,用于显示包含自定义内容的对话框。

Android
Included in Expo Go
Recommended version:
~58.0.1

Expo UI BasicAlertDialog 与官方 Jetpack Compose BasicAlertDialog API 相匹配,可显示一个简约对话框,并接受自定义子组件作为其内容,让你完全掌控对话框的布局

带有自定义内容的 Material 3 基础警告对话框带有自定义内容的 Material 3 基础警告对话框

安装

Terminal
- npx expo install @expo/ui
- yarn expo install @expo/ui
- pnpm expo install @expo/ui
- bun expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

带自定义内容的基础对话框

BasicAlertDialogExample.tsx
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('end')]}> <Text>Confirm</Text> </TextButton> </Column> </Surface> </BasicAlertDialog> )} </Host> ); }

API

import { BasicAlertDialog } from '@expo/ui/jetpack-compose';

Component

BasicAlertDialog

Android

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.

BasicAlertDialogProps

children

Android
Optional • Type: ReactNode

The content to display inside the dialog.

modifiers

Android
Optional • Type: ModifierConfig[]

Modifiers for the component.

onDismissRequest

Android
Optional • Type: () => void

Callback that is called when the user tries to dismiss the dialog (e.g. by tapping outside of it or pressing the back button).

properties

Android
Optional • Type: DialogProperties

Properties for the dialog window.

Types

DialogProperties

Android

Properties for the dialog window, matching DialogProperties in Compose.

PropertyTypeDescription
decorFitsSystemWindows(optional)boolean

Whether the dialog's decor fits system windows (status bar, navigation bar, and more). When true, the dialog's content will be inset to avoid overlapping with system UI.

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