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 apps。
expo-dev-menu 为 React Native 应用提供开发者菜单 UI,其中包括:
- 可通过摇晃手势或三指长按访问的强大且可扩展的菜单 UI
- 快速访问常见开发操作
- 支持自定义菜单项以扩展功能
安装
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);
这将在开发者菜单中创建一个新部分,其中包含你注册的按钮:
注意: 后续调用
registerDevMenuItems将覆盖之前的所有条目。
与 expo-dev-client 一起使用
如果你正在使用开发构建,请改为安装 expo-dev-client。它包含 expo-dev-menu 以及其他开发工具:
- 用于在开发服务器之间切换的可配置启动器 UI
- 改进的调试工具
- 支持从 EAS Update 加载更新
有关更多信息,请查看 expo-dev-client 参考。
API
import * as DevMenu from 'expo-dev-menu';
Methods
A method that closes development client menu when called.
voidA method that hides development client menu when called.
voidA method that opens development client menu when called.
voidSets whether the floating tools button is visible.
void