1# LongPressGesture 2 3**LongPressGesture** is used to trigger a long press gesture, which requires one or more fingers with a minimum 500 ms hold-down time. 4 5> **NOTE** 6> 7> This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8 9 10## APIs 11 12LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number }) 13 14Triggers a long press gesture. In components that support drag actions by default, such as **Text**, **TextInput**, **TextArea**, **HyperLink**, **Image**, and **RichEditor**, the long press gesture may conflict with the drag action. If this occurs, they are handled as follows: 15 16If the minimum duration of the long press gesture is less than 500 ms, the long press gesture receives a higher response priority than the drag action. 17 18If the minimum duration of the long press gesture is greater than or equal to 500 ms, the drag action receives a higher response priority than the long press gesture. 19 20**Atomic service API**: This API can be used in atomic services since API version 11. 21 22**Parameters** 23 24| Name| Type| Mandatory| Description| 25| -------- | -------- | -------- | -------- | 26| fingers | number | No| Minimum number of fingers to trigger a long press gesture. The value ranges from 1 to 10.<br>Default value: **1**<br> **NOTE**<br>If a finger moves more than 15 px after being pressed, the gesture recognition fails.| 27| repeat | boolean | No| Whether to continuously trigger the event callback. The value **true** means to continuously trigger the event callback, and **false** means the opposite.<br>Default value: **false**| 28| duration | number | No| Minimum hold-down time, in ms.<br>Default value: **500**<br>**NOTE**<br>Value range: [0, +∞). If the value is less than or equal to 0, the default value **500** is used.| 29| isFingerCountLimited<sup>15+</sup> | boolean | No| Whether to enforce the exact number of fingers touching the screen. With the value **true**, the gesture recognition fails if the number of fingers touching the screen does not match the configured value of **fingers**.<br>For gestures that have already been successfully recognized, changes in the number of fingers touching the screen will not trigger the repeat event. However, if the number of fingers touching the screen returns to the configured minimum number, the [onAction](ts-basic-gestures-longpressgesture.md#events) event can be triggered. The [onActionEnd](ts-basic-gestures-longpressgesture.md#events) event can also be triggered regardless of the finger count.<br>Default value: **false**| 30 31 32## Events 33 34| Name| Description| 35| -------- | -------- | 36| onAction(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) => void) | Invoked when a long press gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 37| onActionEnd(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) => void) | Invoked when the last finger is lifted after the long press gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 38| onActionCancel(event: () => void) | Invoked when a tap cancellation event is received after the long press gesture is recognized. No gesture event information is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 39| onActionCancel(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) => void)<sup>18+</sup> | Invoked when a tap cancellation event is received after the long press gesture is recognized. Gesture event information is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 40 41## Attributes 42 43| Name| Type |Description | 44| ---- | ------ | ---------------------------------------- | 45| tag<sup>11+</sup> | string | Tag for the long press gesture. It is used to distinguish the gesture during custom gesture judgment.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 46| allowedTypes<sup>14+</sup> | Array\<[SourceTool](ts-gesture-settings.md#sourcetool9)> | Allowed event input types for the long press gesture.<br>**Atomic service API**: This API can be used in atomic services since API version 14.| 47 48 49## Example 50 51This example demonstrates the recognition of a long press gesture using **LongPressGesture**. 52 53```ts 54// xxx.ets 55@Entry 56@Component 57struct LongPressGestureExample { 58 @State count: number = 0 59 60 build() { 61 Column() { 62 Text('LongPress onAction:' + this.count).fontSize(28) 63 // Touch and hold the text with one finger to trigger the gesture event. 64 .gesture( 65 LongPressGesture({ repeat: true }) 66 // When repeat is set to true, the event callback is triggered continuously when the gesture is detected. The triggering interval is specified by duration (500 ms by default). 67 .onAction((event: GestureEvent) => { 68 if (event && event.repeat) { 69 this.count++ 70 } 71 }) 72 // Triggered when the long press gesture ends. 73 .onActionEnd((event: GestureEvent) => { 74 this.count = 0 75 }) 76 ) 77 } 78 .height(200) 79 .width(300) 80 .padding(20) 81 .border({ width: 3 }) 82 .margin(30) 83 } 84} 85``` 86 87 88