This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
ContextMenu
一个用于显示上下文菜单的 SwiftUI ContextMenu 组件。
Expo UI ContextMenu 与官方 SwiftUI contextMenu API 保持一致,并会在长按时显示菜单。对于单击菜单交互,请改用 Menu。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础上下文菜单
带有系统图像的上下文菜单
带有预览的上下文菜单
使用 ContextMenu.Preview 可在打开菜单时在菜单上方显示自定义预览。
带有选择器的上下文菜单
带有分区的上下文菜单
使用 Section 和 Divider 组件来组织菜单项。
禁用项
在菜单 Button 上使用 disabled(true) 修饰符,可将其显示为灰色且不可交互。
可选项(勾选标记)
ContextMenu.Items 中的 SwiftUI Toggle 在 isOn 为 true 时,会自动渲染为左侧带 SF Symbol、右侧带勾选标记的一行。
嵌套上下文菜单
使用嵌套的 ContextMenu 组件来创建子菜单。
API
import { ContextMenu } from '@expo/ui/swift-ui';
Components
Type: React.Element<ContextMenuProps>
ContextMenu allows you to create a context menu, which can be used to provide additional options to the user.
Props of the ContextMenu component.
ReactNodeThe contents of the context menu.
Should include ContextMenu.Trigger, ContextMenu.Items, and optionally ContextMenu.Preview.
Type: React.Element<{
children: ReactNode
}>
Items visible inside the context menu. It could be Section, Divider, Button, Toggle, Picker or even ContextMenu itself for nested menus. Remember to use components from the @expo/ui/swift-ui library.