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 兼容的菜单。
一个与 @react-native-menu/menu API 兼容的 MenuView 组件。支持单击(默认)和长按(shouldOpenOnLongPress)两种触发方式。
在内部,此组件封装了平台特定的 @expo/ui 原语:
- Android: Jetpack Compose 下拉菜单 锚定到内部的
Pressable触发器。 - iOS: SwiftUI 菜单 用于点击触发,以及 SwiftUI 上下文菜单 用于长按触发。
如果你需要更底层的控制,请直接使用这些原语。


安装
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期望的是一个 drawable 资源名称 字符串(例如'ic_menu_add'),它会将其解析到android/app/src/main/res/drawable/。此即插即用实现不会解析 drawable 资源名称——请改为传入ImageSourcePropType(例如require('@expo/material-symbols/edit.xml'))。字符串值在 iOS 上作为 SF Symbol 名称是被接受的。使用Icon.select在每个调用点同时定义两者,这样未使用的一侧就会按平台被 tree-shake 掉。 title仅在 iOS 上作为分组标题渲染;Android 的 MaterialDropdownMenu没有标题槽位。- 在 Android 上,
MenuView会用自己的Pressable包裹触发器来打开菜单,因此你传入作为children的Pressable上绑定的onPress/onLongPress处理器不会触发——外层包装会接管该手势。请将该处理器移到你的onPressAction分支中,或者如果你需要在触发器上保留单击和长按两个独立动作,请使用更底层的DropdownMenu原语。 - 命令式的
ref.show()API 仅限 Android。SwiftUI 的Menu/ContextMenu没有程序化打开 API,因此在 iOS 上该调用是 no-op(并会在开发环境中提示一次警告)。 - 以下来自
@react-native-menu/menu的 props 不受支持:themeVariant、hitSlop、isAnchoredToRight、subtitle、keepsMenuPresented、preferredElementSize,以及state: 'mixed'。
基本用法
将任意视图作为触发器传入。MenuView 会自动附加其自身的点击或长按处理。
长按(上下文菜单)
将 shouldOpenOnLongPress 设置为 true,以以上下文菜单形式渲染。在 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.
() => 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'