This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
菜单
与 @react-native-menu/menu 兼容的菜单。
一个 API 与 @react-native-menu/menu 兼容的 MenuView 组件。支持单击(默认)和长按(shouldOpenOnLongPress)触发。
在底层,此组件封装了平台专属的 @expo/ui 基元:
- Android:Jetpack Compose DropdownMenu,锚定到内部的
Pressable触发器。 - iOS:单击触发时使用 SwiftUI Menu,长按触发时使用 SwiftUI ContextMenu。
如果需要更低层级的控制,请直接使用这些基元。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
从 @react-native-menu/menu 迁移
- 将导入语句从
import { MenuView } from '@react-native-menu/menu'更新为import { MenuView } from '@expo/ui/community/menu'。 - Android 上的
action.image与上游实现不同。@react-native-menu/menu需要一个可绘制资源名称字符串(例如'ic_menu_add'),并根据android/app/src/main/res/drawable/解析该资源。此兼容实现不会解析可绘制资源名称——请改为传入ImageSourcePropType(例如require('@expo/material-symbols/edit.xml'))。iOS 上接受字符串值作为 SF Symbol 名称。使用Icon.select在每个调用位置定义两端的值,以便未使用的平台代码能按平台进行摇树优化。 title仅在 iOS 上渲染为分节标题;Android 的 MaterialDropdownMenu没有标题插槽。- 在 Android 上,
MenuView会将触发器包裹在自己的Pressable中以打开菜单,因此,附加到作为children传入的Pressable上的onPress/onLongPress处理程序不会触发——外层包装器会捕获手势。请改为将处理程序放入onPressAction的分支中;或者,如果需要在触发器上保留独立的单击和长按操作,请使用较低层级的DropdownMenu基元。 - 命令式
ref.show()API 仅适用于 Android。SwiftUIMenu/ContextMenu没有以编程方式打开菜单的 API,因此在 iOS 上调用此方法不会执行任何操作(并会显示一次性开发警告)。 - 不支持
@react-native-menu/menu中的以下属性:themeVariant、hitSlop、isAnchoredToRight、subtitle、keepsMenuPresented、preferredElementSize和state: 'mixed'。
基本用法
将任意视图作为触发器传入。MenuView 会附加自己的单击或长按处理逻辑。
长按(上下文菜单)
设置 shouldOpenOnLongPress,将其渲染为上下文菜单。在 Android 上,同一个受控 DropdownMenu 会在触发器被长按时打开,而不是单击时打开。在 iOS 上,这会使用 SwiftUI 的 ContextMenu,并将触发器显示为模糊预览。
子菜单和内嵌分节
默认情况下,subactions 会将嵌套操作渲染为子菜单。在父项上设置 displayInline: true,则会将子项渲染为内嵌分节,适合用于分组。在 Android 上,只会显示分隔线(Material 的 DropdownMenu 没有分节基元)。在 iOS 上,父项的 title 会成为分节标题。
带勾选标记的切换项
将 state 设置为 'on' 或 'off',可将操作渲染为可切换项;开启时会显示前置勾选标记。选择该操作会触发 onPressAction,调用方负责更新状态。
API
import { MenuView } from '@expo/ui/community/menu';
Component
Type: React.Element<MenuComponentProps & {
ref: Ref<MenuComponentRef>
}>
A drop-in replacement for @react-native-menu/menu's MenuView. Wrap any trigger
view; long-pressing or tapping (per shouldOpenOnLongPress) shows a popup menu
built from the actions tree.
- On Android, renders via Compose's
DropdownMenuanchored to aPressable. - On iOS, renders via SwiftUI's
Menu(tap) orContextMenu(long-press). - On web, the trigger renders the trigger but actions do not fire;
a one-time
console.warnis emitted.
Props
ReactNodeTrigger view. Long-pressing or tapping (per shouldOpenOnLongPress) opens the menu.
ColorSchemeNameThe color scheme of the menu on Android. Omit to follow the device setting.
() => voidCallback invoked when the menu closes (either via dismissal or after an action fires).
On Android, fires from the controlled DropdownMenu's dismiss path.
On iOS, SwiftUI Menu/ContextMenu do not expose a close hook in a way we can
forward, so this is not fired there.
() => voidCallback invoked when the menu opens.
On Android, fires when the trigger's tap/long-press flips expanded to true.
On iOS, SwiftUI Menu/ContextMenu do not expose an open hook, so this is not
fired there.
(event: NativeActionEvent) => voidCallback invoked when a menu action is selected.
boolean • Default: falseWhen true, the menu opens on long-press of the trigger instead of a single tap.
Types
Visual and behavioral attributes of a menu action.
Compatible with @react-native-menu/menu.
Imperative handle exposed by MenuView via ref.
Compatible with @react-native-menu/menu's ref.show() API.
Literal type: string
Selection state for a menu action.
'on' renders a checkmark; 'off' doesn't.
Acceptable values are: 'on' | 'off'