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
一个为调试构建提供开发者菜单的库。
expo-dev-menu 可以在任何 Expo 项目中作为独立库使用。它在不需要完整 expo-dev-client 启动器界面的 brownfield 应用 中尤其有用。
expo-dev-menu 为 React Native 应用提供了一个开发者菜单 UI,其中包括:
- 一个可通过摇动手势或三指长按访问的强大且可扩展的菜单 UI
- 可快速访问常见的开发操作
- 支持自定义菜单项以扩展功能
安装
- npx expo install expo-dev-menuIf 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);
这将在开发菜单中创建一个新的分区,其中包含你已注册的按钮:
注意: 后续对
registerDevMenuItems的调用将覆盖之前的所有条目。
与 expo-dev-client 一起使用
如果你正在使用开发构建,请改为安装 expo-dev-client。它包含 expo-dev-menu 以及其他开发工具:
- 可配置的启动器界面,用于在不同开发服务器之间切换
- 改进的调试工具
- 支持从 EAS Update 加载更新
- npx expo install expo-dev-client有关更多信息,请查看 expo-dev-client 参考文档。
API
import * as DevMenu from 'expo-dev-menu';
Methods
| Parameter | Type |
|---|---|
| items | ExpoDevMenuItem[] |
A method that allows to specify custom entries in the development client menu.
Promise<void>Types
An object representing the custom development client menu entry.
| Property | Type | Description |
|---|---|---|
| callback | () => void | Callback to fire, when user selects an item. |
| name | string | 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 |