This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
警报
一个用于显示原生 iOS 警报对话框的 SwiftUI Alert 组件。
Expo UI Alert 与官方 SwiftUI 警告 API 一致,并会显示一个原生 iOS 警告对话框,其中包含标题、操作按钮以及可选消息。


Alert 是居中的模态对应组件,与 ConfirmationDialog 相对;后者会作为从屏幕底部弹出的操作表呈现。二者共享相同的 trigger/actions/message 插槽模型,因此调用方只需更改组件名称即可在它们之间切换。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基本警告
使用 Alert.Trigger 定义可见元素,并使用 Alert.Actions 提供对话框按钮。
取消和确认
将 role="cancel" 与确认按钮结合使用,以构建标准的“是/否”警告对话框。
破坏性操作
在 Alert.Actions 内的 Button 上使用 role="destructive",将其设置为破坏性操作的样式。
API
import { Alert } from '@expo/ui/swift-ui';
Component
Type: React.Element<AlertProps>
Alert presents a SwiftUI alert with a title, optional message, and action buttons.
See: Official SwiftUI documentation.