1e41f4b71Sopenharmony_ci# Menu Control 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciA context menu – a vertical list of items – can be bound to a component and displayed by long-pressing, clicking, or right-clicking the component. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - **CustomBuilder** does not support the use of **bindMenu** and **bindContextMenu** methods. To display a multi-level menu, use the [Menu](ts-basic-components-menu.md) component instead. 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> - The text in the context menu cannot be selected by long-pressing. 12e41f4b71Sopenharmony_ci> 13e41f4b71Sopenharmony_ci> - Since API version 12, a 500 ms long-press on the menu reveals submenus. 14e41f4b71Sopenharmony_ci> 15e41f4b71Sopenharmony_ci> - Since API version 12, the pressed state of the menu follows finger movement. 16e41f4b71Sopenharmony_ci> 17e41f4b71Sopenharmony_ci> 1. This feature is only available in scenarios where the [Menu](ts-basic-components-menu.md) component is used and the child components include [MenuItem](ts-basic-components-menuitem.md) or [MenuItemGroup](ts-basic-components-menuitemgroup.md). 18e41f4b71Sopenharmony_ci> 19e41f4b71Sopenharmony_ci> 2. This feature is only available for menus with [MenuPreviewMode](#menupreviewmode11) set to **NONE**. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci> 3. The menu animation uses a spring curve. Due to the rebound vibration of the spring curve during the exit, there is a long tail after the menu disappears, which prevents other events from responding. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci## bindMenu 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_cibindMenu(content: Array<MenuElement> | CustomBuilder, options?: MenuOptions) 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciBinds a menu to this component, which is displayed when the user clicks the component. A menu item can be a combination of text and icons or a custom component. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Parameters** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 37e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | -------------------------------------------- | 38e41f4b71Sopenharmony_ci| content | Array<[MenuElement](#menuelement)> \| [CustomBuilder](ts-types.md#custombuilder8) | Yes | Array of menu item icons and text, or custom component.| 39e41f4b71Sopenharmony_ci| options | [MenuOptions](#menuoptions10) | No | Parameters of the context menu. | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci## bindMenu<sup>11+</sup> 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_cibindMenu(isShow: boolean, content: Array<MenuElement> | CustomBuilder, options?: MenuOptions) 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ciBinds a menu to this component, which is displayed when the user clicks the component. A menu item can be a combination of text and icons or a custom component. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**Parameters** 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 54e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 55e41f4b71Sopenharmony_ci| isShow<sup>11+</sup> | boolean | Yes | Whether to show the menu. The default value is **false**. Menus can be displayed only after all pages are constructed. Therefore, this parameter cannot be set to **true** during page construction. Otherwise, display position and shape errors will occur. Two-way binding is not supported.| 56e41f4b71Sopenharmony_ci| content | Array<[MenuElement](#menuelement)> \| [CustomBuilder](ts-types.md#custombuilder8) | Yes | Array of menu item icons and text, or custom component. | 57e41f4b71Sopenharmony_ci| options | [MenuOptions](#menuoptions10) | No | Parameters of the context menu. | 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci## bindContextMenu<sup>8+</sup> 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_cibindContextMenu(content: CustomBuilder, responseType: ResponseType, options?: ContextMenuOptions) 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ciBinds a context menu to this component, which is displayed when the user long-presses or right-clicks the component. Only custom menu items are supported. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**Parameters** 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 72e41f4b71Sopenharmony_ci| ------------ | -------------------------------------------------- | ---- | -------------------------------- | 73e41f4b71Sopenharmony_ci| content | [CustomBuilder](ts-types.md#custombuilder8) | Yes | Builder of the custom menu content. | 74e41f4b71Sopenharmony_ci| responseType | [ResponseType](ts-appendix-enums.md#responsetype8) | Yes | How the context menu is triggered, which can be long-press or right-click. Long pressing with a mouse device is not supported.| 75e41f4b71Sopenharmony_ci| options | [ContextMenuOptions](#contextmenuoptions10) | No | Parameters of the context menu. | 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci## bindContextMenu<sup>12+</sup> 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_cibindContextMenu(isShown: boolean, content: CustomBuilder, options?: ContextMenuOptions) 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciBinds a context menu to the component, whose visibility is subject to the **isShown** settings. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciIf **isShown** is **true**, the menu is displayed. If **isShown** is set to **false**, the menu is hidden. The menu items need to be customized. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciThe position of the context menu is subject to the **placement** settings, rather than where the component is clicked. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**Parameters** 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 95e41f4b71Sopenharmony_ci| ------------ | -------------------------------------------------- | ---- | -------------------------------------------- | 96e41f4b71Sopenharmony_ci| isShown | boolean | Yes | Whether to show the context menu. The value **true** means to show the context menu, and **false** (default) means the opposite. The menu can be displayed properly only when the related page has been built. If this parameter is set to **true** before the build is complete, display issues, such as misplacement, distortion, or failure to pop up, may occur. Currently, two-way data binding is not supported, and dragging cannot be triggered by long press. | 97e41f4b71Sopenharmony_ci| content | [CustomBuilder](ts-types.md#custombuilder8) | Yes | Builder of the custom menu content.| 98e41f4b71Sopenharmony_ci| options | [ContextMenuOptions](#contextmenuoptions10) | No | Parameters of the context menu. | 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci## MenuElement 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 103e41f4b71Sopenharmony_ci| --------------------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 104e41f4b71Sopenharmony_ci| value | [ResourceStr](ts-types.md#resourcestr) | Yes | Menu item text.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 105e41f4b71Sopenharmony_ci| icon<sup>10+</sup> | [ResourceStr](ts-types.md#resourcestr) | No | Menu item icon.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 106e41f4b71Sopenharmony_ci| enabled<sup>11+</sup> | boolean | No | Whether to enable interactions with the menu item.<br>Default value: **true**, indicating that interactions with the menu item are enabled.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 107e41f4b71Sopenharmony_ci| action | () => void | Yes | Action triggered when a menu item is clicked.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 108e41f4b71Sopenharmony_ci| symbolIcon<sup>12+</sup> | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | No | Icon of a menu item. When this parameter is set, the original icon is not displayed.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci## MenuOptions<sup>10+</sup> 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ciInherits from [ContextMenuOptions](#contextmenuoptions10). 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 115e41f4b71Sopenharmony_ci| ----------------------------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 116e41f4b71Sopenharmony_ci| title | [ResourceStr](ts-types.md#resourcestr) | No | Menu title.<br>**NOTE**<br>This parameter is effective only when **content** is set to Array<[MenuElement](#menuelement)>.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 117e41f4b71Sopenharmony_ci| showInSubWindow<sup>11+</sup> | boolean | No | Whether to show the menu in a subwindow.<br>Default value: **true** for 2-in-1 devices and **false** for other devices<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci## ContextMenuOptions<sup>10+</sup> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 122e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 123e41f4b71Sopenharmony_ci| offset | [Position](ts-types.md#position) | No | Offset for showing the context menu, which should not cause the menu to extend beyond the screen.<br>**NOTE**<br>When the menu is displayed relative to the parent component area, the width or height of the area is automatically counted into the offset based on the **placement** attribute of the menu.<br>When the menu is displayed above the parent component (that is, **placement** is set to **Placement.TopLeft**, **Placement.Top**, or **Placement.TopRight**), a positive value of **x** indicates rightward movement relative to the parent component, and a positive value of **y** indicates upward movement.<br>When the menu is displayed below the parent component (that is, **placement** is set to **Placement.BottomLeft**, **Placement.Bottom**, or **Placement.BottomRight**), a positive value of **x** indicates rightward movement relative to the parent component, and a positive value of **y** indicates downward movement.<br>When the menu is displayed on the left of the parent component (that is, **placement** is set to **Placement.LeftTop**, **Placement.Left**, or **Placement.LeftBottom**), a positive value of **x** indicates leftward movement relative to the parent component, and a positive value of **y** indicates downward movement.<br>When the menu is displayed on the right of the parent component (that is, **placement** is set to **Placement.RightTop**, **Placement.Right**, or **Placement.RightBottom**), a positive value of **x** indicates rightward movement relative to the parent component, and a positive value of **y** indicates downward movement.<br>If the display position of the menu is adjusted (different from the main direction of the initial **placement** value), the offset value is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 124e41f4b71Sopenharmony_ci| placement | [Placement](ts-appendix-enums.md#placement8) | No | Preferred position of the context menu. If the set position is insufficient for holding the component, it will be automatically adjusted.<br>**NOTE**<br>Setting **placement** to **undefined** or **null** is equivalent to not setting it at all. In this case, if [bindContextMenu<sup>8+</sup>](#bindcontextmenu8) is used, the menu is displayed at the clicked position; if [bindContextMenu<sup>12+</sup>](#bindcontextmenu12) is used, the default value **Placement.BottomLeft** is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 125e41f4b71Sopenharmony_ci| enableArrow | boolean | No | Whether to display an arrow. If the size and position of the context menu are insufficient for holding an arrow, no arrow is displayed.<br>Default value: **false**, indicating that no arrow is displayed<br>**NOTE**<br>When **enableArrow** is **true**, an arrow is displayed in the position specified by **placement**. If **placement** is not set or its value is invalid, the arrow is displayed above the target. If the position is insufficient for holding the arrow, it is automatically adjusted. When **enableArrow** is **undefined**, no arrow is displayed. This API is supported in **bindContextMenu** since API version 10 and **bindMenu** since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 126e41f4b71Sopenharmony_ci| arrowOffset | [Length](ts-types.md#length) | No | Offset of the arrow relative to the context menu. The offset settings take effect only when the value is valid, can be converted to a number greater than 0, and does not cause the arrow to extend beyond the safe area of the context menu.<br>**NOTE**<br>The safe distance of the arrow from the four sides of the menu is the sum of the menu's corner radius and half the width of the arrow.<br>The value of **placement** determines whether the offset is horizontal or vertical.<br>When the arrow is in the horizontal direction of the menu, the offset is the distance from the arrow to the leftmost arrow's safe distance. When the arrow is in the vertical direction of the menu, the offset is the distance from the arrow to the topmost arrow's safe distance.<br>The default position where the arrow is displayed varies with the value of **placement**:<br>Without any avoidance by the menu, when **placement** is set to **Placement.Top** or **Placement.Bottom**, the arrow is displayed horizontally and is centered by default;<br>when **placement** is set to **Placement.Left** or **Placement.Right**, the arrow is displayed vertically and is centered by default;<br>when **placement** is set to **Placement.TopLeft** or **Placement.BottomLeft**, the arrow is displayed horizontally by default, and the distance from the arrow to the left edge of the menu is the arrow's safe distance;<br>when **placement** is set to **Placement.TopRight** or **Placement.BottomRight**, the arrow is displayed horizontally by default, and the distance from the arrow to the right edge of the menu is the arrow's safe distance;<br>when **placement** is set to **Placement.LeftTop** or **Placement.RightTop**, the arrow is displayed vertically by default, and the distance from the arrow to the top edge of the menu is the arrow's safe distance;<br>when **placement** is set to **Placement.LeftBottom** or **Placement.RightBottom**, the arrow is displayed vertically by default, and the distance from the arrow to the bottom edge of the menu is the arrow's safe distance.<br> This API is supported in **bindContextMenu** since API version 10 and **bindMenu** since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 127e41f4b71Sopenharmony_ci| preview<sup>11+</sup> | [MenuPreviewMode](#menupreviewmode11)\| [CustomBuilder](ts-types.md#custombuilder8) | No | Preview displayed when the context menu is triggered by a long-press or by calling [bindContextMenu<sup>12+</sup>](#bindcontextmenu12). It can be a screenshot of the target component or custom content.<br>Default value: **MenuPreviewMode.NONE**, indicating no preview.<br>**NOTE**<br>- This parameter has no effect when **responseType** is set to **ResponseType.RightClick**.<br>- If **preview** is set to **MenuPreviewMode.NONE** or is not set, the **enableArrow** parameter is effective.<br>- If **preview** is set to **MenuPreviewMode.IMAGE** or **CustomBuilder**, no arrow will be displayed even when **enableArrow** is **true**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 128e41f4b71Sopenharmony_ci| previewAnimationOptions<sup>11+</sup> | [ContextMenuAnimationOptions](#contextmenuanimationoptions11) | No | Start scale ratio and end scale ratio (relative to the original preview image) of the preview animation displayed when the component is long pressed<br>Default value: **{scale: [0.95, 1.1]}**<br>**NOTE**<br>If the value is less than or equal to 0, this parameter does not take effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 129e41f4b71Sopenharmony_ci| onAppear | () => void | No | Callback triggered when the menu is displayed.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 130e41f4b71Sopenharmony_ci| onDisappear | () => void | No | Callback triggered when the menu is hidden.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 131e41f4b71Sopenharmony_ci| aboutToAppear | () => void | No | Callback triggered when the menu is about to appear.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 132e41f4b71Sopenharmony_ci| aboutToDisappear | () => void | No | Callback triggered when the menu is about to disappear.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 133e41f4b71Sopenharmony_ci| backgroundColor<sup>11+</sup> | [ResourceColor](ts-types.md#resourcecolor) | No| Backplane color of the dialog box.<br>Default value: **Color.Transparent**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 134e41f4b71Sopenharmony_ci| backgroundBlurStyle<sup>11+</sup> | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No| Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 135e41f4b71Sopenharmony_ci| transition<sup>12+</sup> | [TransitionEffect](ts-transition-animation-component.md#transitioneffect10)| No | Transition effect for the entrance and exit of the menu.<br>**NOTE**<br>During the exit animation of the menu, if there is a switch between landscape and portrait modes, the menu will make way. Level-2 menus do not inherit custom animations. The level-2 menu can be clicked during the pop-up process, but not during the execution of the exit animation.<br>For details, see [TransitionEffect](ts-transition-animation-component.md#transitioneffect10).<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 136e41f4b71Sopenharmony_ci| borderRadius<sup>12+</sup> | [Length](ts-types.md#length) \| [BorderRadiuses](ts-types.md#borderradiuses9) \| [LocalizedBorderRadiuses](ts-types.md#localizedborderradiuses12) | No | Border radius of the menu.<br>**NOTE**<br> The value cannot be in percentage.<br>If the sum of the two maximum corner radii in the horizontal direction exceeds the menu's width, or if the sum of the two maximum corner radii in the vertical direction exceeds the menu's height, the default corner radius of the menu will be used.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci## MenuPreviewMode<sup>11+</sup> 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| Name | Description | 145e41f4b71Sopenharmony_ci| ----- | -------------------------------------- | 146e41f4b71Sopenharmony_ci| NONE | No preview is displayed. | 147e41f4b71Sopenharmony_ci| IMAGE | The preview is a screenshot of the component on which a long-press triggers the context menu.| 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci## ContextMenuAnimationOptions<sup>11+</sup> 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 154e41f4b71Sopenharmony_ci| ----- | ------------------------------------------ | ---- | ------------------------------------ | 155e41f4b71Sopenharmony_ci| scale | [AnimationRange](#animationrange11)\<number> | No | Scale ratio of the preview image when the animation starts and scale ratio when the animation ends.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 156e41f4b71Sopenharmony_ci| transition<sup>12+</sup> | [TransitionEffect](ts-transition-animation-component.md#transitioneffect10)| No | Transition effect for the entrance and exit of the menu.<br>**NOTE**<br>During the exit animation of the menu, if there is a switch between landscape and portrait modes, the menu will make way. Level-2 menus do not inherit custom animations. The level-2 menu can be clicked during the pop-up process, but not during the execution of the exit animation.<br>For details, see [TransitionEffect](ts-transition-animation-component.md#transitioneffect10).| 157e41f4b71Sopenharmony_ci| hoverScale<sup>12+</sup> | [AnimationRange](#animationrange11)\<number> | No | Sets the scale ratio of the original component snapshot to the preview image at the beginning and end of the scale animation in a custom long press scenario. There is a transition animation for the switch with the preview image.<br>**NOTE**<br> If the value is less than or equal to 0, this API does not take effect.<br>This API does not take effect in [bindContextMenu<sup>12+</sup>](#bindcontextmenu12) scenarios.<br> This API does not take effect when **transition** is set.<br> If this API and the **scale** API are used at the same time, the start value of the **scale** API does not take effect.<br> To ensure the optimal experience, it is not recommended that the final preview image size be smaller than the size of the original component snapshot. The width and height of the preview animation are affected by the component snapshot and the custom preview size. Verify the display effect based on the actual use case.| 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci## AnimationRange<sup>11+</sup> 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ciDescribes the scale ratio relative to the preview image at the beginning and end of the scale animation. 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci| Value Range | Description | 168e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------------------------------ | 169e41f4b71Sopenharmony_ci| [from: T, to: T] | **from** indicates the scale ratio at the beginning of the animation, and **to** indicates the scale ratio at the end of the animation.| 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci## Example 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci### Example 1 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ciMenu with textual menu items: 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci```ts 178e41f4b71Sopenharmony_ci// xxx.ets 179e41f4b71Sopenharmony_ci@Entry 180e41f4b71Sopenharmony_ci@Component 181e41f4b71Sopenharmony_cistruct MenuExample { 182e41f4b71Sopenharmony_ci build() { 183e41f4b71Sopenharmony_ci Column() { 184e41f4b71Sopenharmony_ci Text('click for Menu') 185e41f4b71Sopenharmony_ci .bindMenu([ 186e41f4b71Sopenharmony_ci { 187e41f4b71Sopenharmony_ci value: 'Menu1', 188e41f4b71Sopenharmony_ci action: () => { 189e41f4b71Sopenharmony_ci console.info('handle Menu1 select') 190e41f4b71Sopenharmony_ci } 191e41f4b71Sopenharmony_ci }, 192e41f4b71Sopenharmony_ci { 193e41f4b71Sopenharmony_ci value: 'Menu2', 194e41f4b71Sopenharmony_ci action: () => { 195e41f4b71Sopenharmony_ci console.info('handle Menu2 select') 196e41f4b71Sopenharmony_ci } 197e41f4b71Sopenharmony_ci }, 198e41f4b71Sopenharmony_ci ]) 199e41f4b71Sopenharmony_ci } 200e41f4b71Sopenharmony_ci .width('100%') 201e41f4b71Sopenharmony_ci .margin({ top: 5 }) 202e41f4b71Sopenharmony_ci } 203e41f4b71Sopenharmony_ci} 204e41f4b71Sopenharmony_ci``` 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci### Example 2 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ciMenu with custom menu items: 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci```ts 213e41f4b71Sopenharmony_ci@Entry 214e41f4b71Sopenharmony_ci@Component 215e41f4b71Sopenharmony_cistruct MenuExample { 216e41f4b71Sopenharmony_ci @State listData: number[] = [0, 0, 0] 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci @Builder MenuBuilder() { 219e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 220e41f4b71Sopenharmony_ci ForEach(this.listData, (item:number, index) => { 221e41f4b71Sopenharmony_ci Column() { 222e41f4b71Sopenharmony_ci Row() { 223e41f4b71Sopenharmony_ci Image($r("app.media.icon")).width(20).height(20).margin({ right: 5 }) 224e41f4b71Sopenharmony_ci Text(`Menu${index as number + 1}`).fontSize(20) 225e41f4b71Sopenharmony_ci } 226e41f4b71Sopenharmony_ci .width('100%') 227e41f4b71Sopenharmony_ci .height(30) 228e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 229e41f4b71Sopenharmony_ci .align(Alignment.Center) 230e41f4b71Sopenharmony_ci .onClick(() => { 231e41f4b71Sopenharmony_ci console.info(`Menu${index as number + 1} Clicked!`) 232e41f4b71Sopenharmony_ci }) 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci if (index != this.listData.length - 1) { 235e41f4b71Sopenharmony_ci Divider().height(10).width('80%').color('#ccc') 236e41f4b71Sopenharmony_ci } 237e41f4b71Sopenharmony_ci }.padding(5).height(40) 238e41f4b71Sopenharmony_ci }) 239e41f4b71Sopenharmony_ci }.width(100) 240e41f4b71Sopenharmony_ci } 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci build() { 243e41f4b71Sopenharmony_ci Column() { 244e41f4b71Sopenharmony_ci Text('click for menu') 245e41f4b71Sopenharmony_ci .fontSize(20) 246e41f4b71Sopenharmony_ci .margin({ top: 20 }) 247e41f4b71Sopenharmony_ci .bindMenu(this.MenuBuilder) 248e41f4b71Sopenharmony_ci } 249e41f4b71Sopenharmony_ci .height('100%') 250e41f4b71Sopenharmony_ci .width('100%') 251e41f4b71Sopenharmony_ci .backgroundColor('#f0f0f0') 252e41f4b71Sopenharmony_ci } 253e41f4b71Sopenharmony_ci} 254e41f4b71Sopenharmony_ci``` 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci### Example 3 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ciContext menu displayed upon long-press: 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci```ts 263e41f4b71Sopenharmony_ci// xxx.ets 264e41f4b71Sopenharmony_ci@Entry 265e41f4b71Sopenharmony_ci@Component 266e41f4b71Sopenharmony_cistruct ContextMenuExample { 267e41f4b71Sopenharmony_ci @Builder MenuBuilder() { 268e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 269e41f4b71Sopenharmony_ci Text('Test menu item 1') 270e41f4b71Sopenharmony_ci .fontSize(20) 271e41f4b71Sopenharmony_ci .width(100) 272e41f4b71Sopenharmony_ci .height(50) 273e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 274e41f4b71Sopenharmony_ci Divider().height(10) 275e41f4b71Sopenharmony_ci Text('Test menu item 2') 276e41f4b71Sopenharmony_ci .fontSize(20) 277e41f4b71Sopenharmony_ci .width(100) 278e41f4b71Sopenharmony_ci .height(50) 279e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 280e41f4b71Sopenharmony_ci }.width(100) 281e41f4b71Sopenharmony_ci } 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci build() { 284e41f4b71Sopenharmony_ci Column() { 285e41f4b71Sopenharmony_ci Text('LongPress for menu') 286e41f4b71Sopenharmony_ci } 287e41f4b71Sopenharmony_ci .width('100%') 288e41f4b71Sopenharmony_ci .margin({ top: 5 }) 289e41f4b71Sopenharmony_ci .bindContextMenu(this.MenuBuilder, ResponseType.LongPress) 290e41f4b71Sopenharmony_ci } 291e41f4b71Sopenharmony_ci} 292e41f4b71Sopenharmony_ci``` 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci### Example 4 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ciDirective menu displayed upon right-click: 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci```ts 301e41f4b71Sopenharmony_ci// xxx.ets 302e41f4b71Sopenharmony_ci@Entry 303e41f4b71Sopenharmony_ci@Component 304e41f4b71Sopenharmony_cistruct DirectiveMenuExample { 305e41f4b71Sopenharmony_ci @Builder MenuBuilder() { 306e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 307e41f4b71Sopenharmony_ci Text('Options') 308e41f4b71Sopenharmony_ci Divider().strokeWidth(2).margin(5).color('#F0F0F0') 309e41f4b71Sopenharmony_ci Text('Hide') 310e41f4b71Sopenharmony_ci Divider().strokeWidth(2).margin(5).color('#F0F0F0') 311e41f4b71Sopenharmony_ci Text('Exit') 312e41f4b71Sopenharmony_ci } 313e41f4b71Sopenharmony_ci .width(200) 314e41f4b71Sopenharmony_ci } 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci build() { 317e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 318e41f4b71Sopenharmony_ci Column() { 319e41f4b71Sopenharmony_ci Text("DirectiveMenuExample") 320e41f4b71Sopenharmony_ci .fontSize(20) 321e41f4b71Sopenharmony_ci .width('100%') 322e41f4b71Sopenharmony_ci .height("25%") 323e41f4b71Sopenharmony_ci .backgroundColor('#F0F0F0') 324e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 325e41f4b71Sopenharmony_ci .bindContextMenu(this.MenuBuilder, ResponseType.RightClick, { 326e41f4b71Sopenharmony_ci enableArrow: true, 327e41f4b71Sopenharmony_ci placement: Placement.Bottom 328e41f4b71Sopenharmony_ci }) 329e41f4b71Sopenharmony_ci } 330e41f4b71Sopenharmony_ci } 331e41f4b71Sopenharmony_ci .width('100%') 332e41f4b71Sopenharmony_ci .height('100%') 333e41f4b71Sopenharmony_ci } 334e41f4b71Sopenharmony_ci} 335e41f4b71Sopenharmony_ci``` 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci### Example 5 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciContext menu displayed upon long-pressing (with preview of component screenshot): 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci```ts 344e41f4b71Sopenharmony_ci// xxx.ets 345e41f4b71Sopenharmony_ci@Entry 346e41f4b71Sopenharmony_ci@Component 347e41f4b71Sopenharmony_cistruct Index { 348e41f4b71Sopenharmony_ci private iconStr: ResourceStr = $r("app.media.icon") 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci @Builder 351e41f4b71Sopenharmony_ci MyMenu() { 352e41f4b71Sopenharmony_ci Menu() { 353e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 354e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 355e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 356e41f4b71Sopenharmony_ci } 357e41f4b71Sopenharmony_ci } 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci build() { 360e41f4b71Sopenharmony_ci Column({ space: 50 }) { 361e41f4b71Sopenharmony_ci Column() { 362e41f4b71Sopenharmony_ci Column() { 363e41f4b71Sopenharmony_ci Text('preview-image') 364e41f4b71Sopenharmony_ci .width(200) 365e41f4b71Sopenharmony_ci .height(100) 366e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 367e41f4b71Sopenharmony_ci .margin(100) 368e41f4b71Sopenharmony_ci .fontSize(30) 369e41f4b71Sopenharmony_ci .bindContextMenu(this.MyMenu, ResponseType.LongPress, 370e41f4b71Sopenharmony_ci { preview: MenuPreviewMode.IMAGE, 371e41f4b71Sopenharmony_ci previewAnimationOptions: {scale: [0.8, 1.0]}, 372e41f4b71Sopenharmony_ci }) 373e41f4b71Sopenharmony_ci .backgroundColor("#ff3df2f5") 374e41f4b71Sopenharmony_ci } 375e41f4b71Sopenharmony_ci }.width('100%') 376e41f4b71Sopenharmony_ci } 377e41f4b71Sopenharmony_ci } 378e41f4b71Sopenharmony_ci} 379e41f4b71Sopenharmony_ci``` 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci### Example 6 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ciContext menu displayed upon long-pressing (with preview of custom content): 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci```ts 388e41f4b71Sopenharmony_ci// xxx.ets 389e41f4b71Sopenharmony_ci@Entry 390e41f4b71Sopenharmony_ci@Component 391e41f4b71Sopenharmony_cistruct Index { 392e41f4b71Sopenharmony_ci private iconStr: ResourceStr = $r("app.media.icon") 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci @Builder 395e41f4b71Sopenharmony_ci MyMenu() { 396e41f4b71Sopenharmony_ci Menu() { 397e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 398e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 399e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 400e41f4b71Sopenharmony_ci } 401e41f4b71Sopenharmony_ci } 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci @Builder 404e41f4b71Sopenharmony_ci MyPreview() { 405e41f4b71Sopenharmony_ci Column() { 406e41f4b71Sopenharmony_ci Image($r('app.media.icon')) 407e41f4b71Sopenharmony_ci .width(200) 408e41f4b71Sopenharmony_ci .height(200) 409e41f4b71Sopenharmony_ci } 410e41f4b71Sopenharmony_ci } 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci build() { 413e41f4b71Sopenharmony_ci Column({ space: 50 }) { 414e41f4b71Sopenharmony_ci Column() { 415e41f4b71Sopenharmony_ci Column() { 416e41f4b71Sopenharmony_ci Text('preview-builder') 417e41f4b71Sopenharmony_ci .width(200) 418e41f4b71Sopenharmony_ci .height(100) 419e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 420e41f4b71Sopenharmony_ci .margin(100) 421e41f4b71Sopenharmony_ci .fontSize(30) 422e41f4b71Sopenharmony_ci .bindContextMenu(this.MyMenu, ResponseType.LongPress, 423e41f4b71Sopenharmony_ci { 424e41f4b71Sopenharmony_ci preview: this.MyPreview 425e41f4b71Sopenharmony_ci }) 426e41f4b71Sopenharmony_ci } 427e41f4b71Sopenharmony_ci }.width('100%') 428e41f4b71Sopenharmony_ci } 429e41f4b71Sopenharmony_ci } 430e41f4b71Sopenharmony_ci} 431e41f4b71Sopenharmony_ci``` 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci### Example 7 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ciContext menu displayed upon setting isShown (with preview of custom content): 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci```ts 440e41f4b71Sopenharmony_ci// xxx.ets 441e41f4b71Sopenharmony_ci@Entry 442e41f4b71Sopenharmony_ci@Component 443e41f4b71Sopenharmony_cistruct Index { 444e41f4b71Sopenharmony_ci private iconStr: ResourceStr = $r("app.media.icon") 445e41f4b71Sopenharmony_ci @State isShown: boolean = false 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci @Builder 448e41f4b71Sopenharmony_ci MyMenu() { 449e41f4b71Sopenharmony_ci Menu() { 450e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 451e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 452e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 453e41f4b71Sopenharmony_ci } 454e41f4b71Sopenharmony_ci } 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci @Builder 457e41f4b71Sopenharmony_ci MyPreview() { 458e41f4b71Sopenharmony_ci Column() { 459e41f4b71Sopenharmony_ci Image($r('app.media.icon')) 460e41f4b71Sopenharmony_ci .width(200) 461e41f4b71Sopenharmony_ci .height(200) 462e41f4b71Sopenharmony_ci } 463e41f4b71Sopenharmony_ci } 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci build() { 466e41f4b71Sopenharmony_ci Column({ space: 50 }) { 467e41f4b71Sopenharmony_ci Column() { 468e41f4b71Sopenharmony_ci Column() { 469e41f4b71Sopenharmony_ci Text('preview-builder') 470e41f4b71Sopenharmony_ci .width(200) 471e41f4b71Sopenharmony_ci .height(100) 472e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 473e41f4b71Sopenharmony_ci .margin(100) 474e41f4b71Sopenharmony_ci .fontSize(30) 475e41f4b71Sopenharmony_ci .bindContextMenu(this.isShown, this.MyMenu, 476e41f4b71Sopenharmony_ci { 477e41f4b71Sopenharmony_ci preview: this.MyPreview, 478e41f4b71Sopenharmony_ci onDisappear: ()=>{ 479e41f4b71Sopenharmony_ci this.isShown = false; 480e41f4b71Sopenharmony_ci } 481e41f4b71Sopenharmony_ci }) 482e41f4b71Sopenharmony_ci Button('click') 483e41f4b71Sopenharmony_ci .onClick(()=>{ 484e41f4b71Sopenharmony_ci this.isShown = true; 485e41f4b71Sopenharmony_ci }) 486e41f4b71Sopenharmony_ci } 487e41f4b71Sopenharmony_ci }.width('100%') 488e41f4b71Sopenharmony_ci } 489e41f4b71Sopenharmony_ci } 490e41f4b71Sopenharmony_ci} 491e41f4b71Sopenharmony_ci``` 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci### Example 8 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ciThis example customizes the display and exit animation effects of the menu and preview through the **transition** attribute. 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci```ts 498e41f4b71Sopenharmony_ci// xxx.ets 499e41f4b71Sopenharmony_ci@Entry 500e41f4b71Sopenharmony_ci@Component 501e41f4b71Sopenharmony_cistruct MenuExample { 502e41f4b71Sopenharmony_ci @Builder MenuBuilder() { 503e41f4b71Sopenharmony_ci Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 504e41f4b71Sopenharmony_ci Text('Test menu item 1') 505e41f4b71Sopenharmony_ci .fontSize(12) 506e41f4b71Sopenharmony_ci .width(200) 507e41f4b71Sopenharmony_ci .height(30) 508e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 509e41f4b71Sopenharmony_ci Divider().height(10) 510e41f4b71Sopenharmony_ci Text('Test menu item 2') 511e41f4b71Sopenharmony_ci .fontSize(12) 512e41f4b71Sopenharmony_ci .width(100) 513e41f4b71Sopenharmony_ci .height(30) 514e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 515e41f4b71Sopenharmony_ci }.width(100) 516e41f4b71Sopenharmony_ci } 517e41f4b71Sopenharmony_ci @Builder 518e41f4b71Sopenharmony_ci MyPreview() { 519e41f4b71Sopenharmony_ci Column() { 520e41f4b71Sopenharmony_ci Image($r('app.media.icon')) 521e41f4b71Sopenharmony_ci .width(50) 522e41f4b71Sopenharmony_ci .height(50) 523e41f4b71Sopenharmony_ci } 524e41f4b71Sopenharmony_ci } 525e41f4b71Sopenharmony_ci @State isShow:boolean = false 526e41f4b71Sopenharmony_ci private iconStr: ResourceStr = $r("app.media.icon") 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci @Builder 529e41f4b71Sopenharmony_ci MyMenu() { 530e41f4b71Sopenharmony_ci Menu() { 531e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 532e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 533e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 534e41f4b71Sopenharmony_ci } 535e41f4b71Sopenharmony_ci } 536e41f4b71Sopenharmony_ci build() { 537e41f4b71Sopenharmony_ci Column() { 538e41f4b71Sopenharmony_ci Button('LongPress bindContextMenu') 539e41f4b71Sopenharmony_ci .margin({ top: 15 }) 540e41f4b71Sopenharmony_ci .bindContextMenu( 541e41f4b71Sopenharmony_ci this.MenuBuilder, 542e41f4b71Sopenharmony_ci ResponseType.LongPress,{ 543e41f4b71Sopenharmony_ci transition: TransitionEffect.OPACITY.animation({ duration: 4000, curve: Curve.Ease }).combine( 544e41f4b71Sopenharmony_ci TransitionEffect.rotate({ z: 1, angle: 180 })), 545e41f4b71Sopenharmony_ci preview: this.MyPreview, 546e41f4b71Sopenharmony_ci previewAnimationOptions: { 547e41f4b71Sopenharmony_ci scale: [0.8, 1.0], 548e41f4b71Sopenharmony_ci transition: TransitionEffect.OPACITY.animation({ duration: 4000, curve: Curve.Ease }).combine( 549e41f4b71Sopenharmony_ci TransitionEffect.rotate({ z: 1, angle: 180 })) 550e41f4b71Sopenharmony_ci } 551e41f4b71Sopenharmony_ci }) 552e41f4b71Sopenharmony_ci } 553e41f4b71Sopenharmony_ci .width('100%') 554e41f4b71Sopenharmony_ci .margin({ top: 5 }) 555e41f4b71Sopenharmony_ci } 556e41f4b71Sopenharmony_ci} 557e41f4b71Sopenharmony_ci``` 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci### Example 9 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ciThis example demonstrates a regular menu (using symbol-type icons). 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci```ts 566e41f4b71Sopenharmony_ci// xxx.ets 567e41f4b71Sopenharmony_ciimport { SymbolGlyphModifier } from '@kit.ArkUI'; 568e41f4b71Sopenharmony_ci@Entry 569e41f4b71Sopenharmony_ci@Component 570e41f4b71Sopenharmony_cistruct MenuExample { 571e41f4b71Sopenharmony_ci @State symbolIconModifier1: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_photo')).fontSize('24vp'); 572e41f4b71Sopenharmony_ci @State symbolIconModifier2: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_photo')).fontSize('24vp'); 573e41f4b71Sopenharmony_ci build() { 574e41f4b71Sopenharmony_ci Column() { 575e41f4b71Sopenharmony_ci Text('click for Menu') 576e41f4b71Sopenharmony_ci } 577e41f4b71Sopenharmony_ci .width('100%') 578e41f4b71Sopenharmony_ci .margin({ top: 5 }) 579e41f4b71Sopenharmony_ci .bindMenu([ 580e41f4b71Sopenharmony_ci { 581e41f4b71Sopenharmony_ci value: 'Menu1', 582e41f4b71Sopenharmony_ci symbolIcon:this.symbolIconModifier1, 583e41f4b71Sopenharmony_ci action: () => { 584e41f4b71Sopenharmony_ci console.info('handle Menu1 select') 585e41f4b71Sopenharmony_ci } 586e41f4b71Sopenharmony_ci }, 587e41f4b71Sopenharmony_ci { 588e41f4b71Sopenharmony_ci value: 'Menu2', 589e41f4b71Sopenharmony_ci symbolIcon:this.symbolIconModifier2, 590e41f4b71Sopenharmony_ci action: () => { 591e41f4b71Sopenharmony_ci console.info('handle Menu2 select') 592e41f4b71Sopenharmony_ci } 593e41f4b71Sopenharmony_ci }, 594e41f4b71Sopenharmony_ci ]) 595e41f4b71Sopenharmony_ci } 596e41f4b71Sopenharmony_ci} 597e41f4b71Sopenharmony_ci``` 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci### Example 10 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ciThis example uses **hoverScale** to implement the transition from the component snapshot to the custom preview image. 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci```ts 606e41f4b71Sopenharmony_ci// xxx.ets 607e41f4b71Sopenharmony_ci@Entry 608e41f4b71Sopenharmony_ci@Component 609e41f4b71Sopenharmony_cistruct Index { 610e41f4b71Sopenharmony_ci private iconStr: ResourceStr = $r("app.media.app_icon") 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci @Builder 613e41f4b71Sopenharmony_ci MyMenu() { 614e41f4b71Sopenharmony_ci Menu() { 615e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 616e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 617e41f4b71Sopenharmony_ci MenuItem({ startIcon: this.iconStr, content: "Menu option" }) 618e41f4b71Sopenharmony_ci } 619e41f4b71Sopenharmony_ci } 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci @Builder 622e41f4b71Sopenharmony_ci MyPreview() { 623e41f4b71Sopenharmony_ci Column() { 624e41f4b71Sopenharmony_ci Image($r('app.media.example')) 625e41f4b71Sopenharmony_ci .width(200) 626e41f4b71Sopenharmony_ci .height(200) 627e41f4b71Sopenharmony_ci } 628e41f4b71Sopenharmony_ci } 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci build() { 631e41f4b71Sopenharmony_ci Column({ space: 50 }) { 632e41f4b71Sopenharmony_ci Column() { 633e41f4b71Sopenharmony_ci Column() { 634e41f4b71Sopenharmony_ci Image($r('app.media.example')) 635e41f4b71Sopenharmony_ci .width(100) 636e41f4b71Sopenharmony_ci .height(100) 637e41f4b71Sopenharmony_ci .margin(100) 638e41f4b71Sopenharmony_ci .bindContextMenu(this.MyMenu, ResponseType.LongPress, 639e41f4b71Sopenharmony_ci { 640e41f4b71Sopenharmony_ci preview: this.MyPreview, 641e41f4b71Sopenharmony_ci previewAnimationOptions: { 642e41f4b71Sopenharmony_ci hoverScale: [1.0, 0.95] 643e41f4b71Sopenharmony_ci } 644e41f4b71Sopenharmony_ci }) 645e41f4b71Sopenharmony_ci } 646e41f4b71Sopenharmony_ci }.width('100%') 647e41f4b71Sopenharmony_ci } 648e41f4b71Sopenharmony_ci } 649e41f4b71Sopenharmony_ci} 650e41f4b71Sopenharmony_ci``` 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci 653