A menu is a pop-up window that allows users to perform specific actions. It typically appears when users right-click, long-press, or touch an item.
| API | Use Case |
|---|---|
| Menu control (Menu) | Used to bind actions to specified components, such as displaying operation options when an icon is long-pressed. |
| Global menu independent of UI components (openMenu) | Used to provide operation options in scenarios where UI components cannot be directly accessed, for example, in event callbacks. |
When bindMenu is triggered via the isShow parameter or bindContextMenu is triggered via the isShown parameter, the menu requires complete page construction before display. Therefore, avoid setting isShow or isShown to true during the page build phase, as this may cause incorrect menu positioning and rendering.
When using openMenu, you must provide valid TargetInfo. Otherwise, the menu won't display correctly.
For details about other specifications, see Menu Control and openMenu.
The normal sequence is aboutToAppear > onWillAppear > onAppear > onDidAppear > aboutToDisappear > onWillDisappear > onDisappear > onDidDisappear.
| Name | Type | Description |
|---|---|---|
| aboutToAppear | () => void | Callback invoked when the menu is about to appear. |
| onAppear | () => void | Callback invoked after the menu appears. |
| aboutToDisappear | () => void | Callback invoked when the menu is about to disappear. |
| onDisappear | () => void | Callback invoked after the menu disappears. |
| onWillAppear | Callback<void> | Event callback before the menu display animation starts. Note: aboutToAppear is triggered during initialization, while onWillAppear is triggered before the animation starts. onWillAppear is executed after aboutToAppear. |
| onDidAppear | Callback<void> | Event callback after the menu pops up. Note: 1. When you tap the button quickly, the menu pops up and disappears rapidly. In this case, onWillDisappear may take effect before onDidAppear. 2. If the menu is closed before the entrance animation completes, this callback is not triggered. 3. onAppear and onDidAppear share the same trigger timing, and onDidAppear takes effect after onAppear. |
| onWillDisappear | Callback<void> | Event callback before the menu exit animation starts. Note: 1. When you tap the button quickly, the menu pops up and disappears rapidly. In this case, onWillDisappear may take effect before onDidAppear. 2. aboutToDisappear and onWillDisappear share the same trigger timing, and onWillDisappear takes effect after aboutToDisappear. |
| onDidDisappear | Callback<void> | Event callback after the menu disappears. Note: onDisappear and onDidDisappear share the same trigger timing, and onDidDisappear takes effect after onDisappear. |