Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo DevMenu

一个为调试版本提供开发者菜单的库。

Android
iOS
tvOS

expo-dev-menu 可作为任何 Expo 项目中的独立库使用。它特别适用于不需要完整 expo-dev-client 启动器界面的 brownfield apps。

expo-dev-menu 为 React Native 应用提供开发者菜单 UI,其中包括:

  • 可通过摇晃手势或三指长按访问的强大且可扩展的菜单 UI
  • 快速访问常见开发操作
  • 支持自定义菜单项以扩展功能

安装

Terminal
- npx expo install expo-dev-menu
- yarn expo install expo-dev-menu
- pnpm expo install expo-dev-menu
- bun expo install expo-dev-menu

If you are installing this in an existing React Native app, make sure to install expo in your project.

使用

安装完成后,开发者菜单将在调试构建中可用。你可以通过以下方式打开它:

  • 摇晃手势:摇晃设备
  • 三指长按:在屏幕上用三根手指长按
  • 以编程方式:在代码中调用 DevMenu.openMenu()

扩展开发者菜单

可以使用 registerDevMenuItems API 为开发者菜单添加额外按钮:

import { registerDevMenuItems } from 'expo-dev-menu'; const devMenuItems = [ { name: 'My Custom Button', callback: () => console.log('Hello world!'), }, ]; registerDevMenuItems(devMenuItems);

这将在开发者菜单中创建一个新部分,其中包含你注册的按钮:

与 expo-dev-client 一起使用

如果你正在使用开发构建,请改为安装 expo-dev-client。它包含 expo-dev-menu 以及其他开发工具:

  • 用于在开发服务器之间切换的可配置启动器 UI
  • 改进的调试工具
  • 支持从 EAS Update 加载更新
Terminal
- npx expo install expo-dev-client
- yarn expo install expo-dev-client
- pnpm expo install expo-dev-client
- bun expo install expo-dev-client

有关更多信息,请查看 expo-dev-client 参考。

API

import * as DevMenu from 'expo-dev-menu';

Methods

DevMenu.closeMenu()

Android
iOS
tvOS

A method that closes development client menu when called.

Returns:
void

DevMenu.hideMenu()

Android
iOS
tvOS

A method that hides development client menu when called.

Returns:
void

DevMenu.openMenu()

Android
iOS
tvOS

A method that opens development client menu when called.

Returns:
void

DevMenu.registerDevMenuItems(items)

Android
iOS
tvOS
ParameterType
itemsExpoDevMenuItem[]

A method that allows to specify custom entries in the development client menu.

Returns:
Promise<void>

DevMenu.setToolsButtonVisible(visible)

Android
iOS
tvOS
ParameterType
visibleboolean

Sets whether the floating tools button is visible.

Returns:
void

Types

ExpoDevMenuItem

Android
iOS
tvOS

An object representing the custom development client menu entry.

PropertyTypeDescription
callback() => void

Callback to fire, when user selects an item.

namestring

Name of the entry, will be used as label.

shouldCollapse(optional)boolean

A boolean specifying if the menu should close after the user interaction.

Default:false