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).
上下文菜单
一个用于显示上下文菜单的 SwiftUI 上下文菜单组件。
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.