Expo DevMenu
一个为调试构建提供开发者菜单的库。
expo-dev-menu 可以作为任何 Expo 项目的 独立库 使用。它在不需要完整 expo-dev-client 启动器界面的 brownfield 应用 中尤其有用。
🌐 The expo-dev-menu can be used as a standalone library in any Expo project. It is especially useful in brownfield apps that don't need the full expo-dev-client launcher interface.
expo-dev-menu 为 React Native 应用提供了一个开发者菜单界面,包含:
- 一个强大且可扩展的菜单界面,可以通过摇晃手势或三指长按来访问
- 快速访问常用开发操作
- 支持自定义菜单项以扩展功能
安装
🌐 Installation
- npx expo install expo-dev-menuIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
安装后,开发者菜单将在你的调试版本中可用。你可以通过以下方式打开它:
🌐 Once installed, the developer menu is available in your debug builds. You can open it by:
- 摇动手势:摇动你的设备
- 三指长按:在屏幕上用三根手指长按
- 以编程方式:从你的代码中调用
DevMenu.openMenu()
扩展开发菜单
🌐 Extending the dev menu
可以使用 registerDevMenuItems API 扩展开发者菜单,以包含额外的按钮:
🌐 The dev menu can be extended to include extra buttons by using the registerDevMenuItems API:
import { registerDevMenuItems } from 'expo-dev-menu'; const devMenuItems = [ { name: 'My Custom Button', callback: () => console.log('Hello world!'), }, ]; registerDevMenuItems(devMenuItems);
这将在开发菜单中创建一个新部分,其中包含你已注册的按钮:
🌐 This will create a new section in the dev menu that includes the buttons you have registered:
注意: 后续对
registerDevMenuItems的调用将覆盖之前的所有条目。
与 expo-dev-client 一起使用
🌐 Using with expo-dev-client
如果你正在使用开发版本,请改为安装 expo-dev-client。它包含 expo-dev-menu 以及其他开发工具:
🌐 If you are using development builds, install expo-dev-client instead. It includes expo-dev-menu along with additional development tools:
- 一个用于在开发服务器之间切换的可配置启动器界面
- 改进的调试工具
- 支持从 EAS 更新 加载更新
- npx expo install expo-dev-client欲了解更多信息,请查看 expo-dev-client 参考。
🌐 For more information, check the expo-dev-client reference.
应用接口
🌐 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.
void| 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 |