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.