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.<br>Default value: **false**|
28| duration | number | No| Minimum hold-down time, in ms.<br>Default value: **500**<br>**NOTE**<br>If the value is less than or equal to 0, the default value **500** will be used.|
29
30
31## Events
32
33| Name| Description|
34| -------- | -------- |
35| onAction(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; 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.|
36| onActionEnd(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; 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.|
37| onActionCancel(event: () =&gt; void) | Invoked when a tap cancellation event is received after the long press gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
38
39## Attributes
40
41| Name| Type   |Description                                       |
42| ----  | ------  | ---------------------------------------- |
43| 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.|
44| 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.|
45
46
47## Example
48
49This example demonstrates the recognition of a long press gesture using **TapGesture**.
50
51```ts
52// xxx.ets
53@Entry
54@Component
55struct LongPressGestureExample {
56  @State count: number = 0
57
58  build() {
59    Column() {
60      Text('LongPress onAction:' + this.count).fontSize(28)
61        // Touch and hold the text with one finger to trigger the gesture event.
62        .gesture(
63        LongPressGesture({ repeat: true })
64          // 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).
65          .onAction((event: GestureEvent) => {
66            if (event && event.repeat) {
67              this.count++
68            }
69          })
70            // Triggered when the long press gesture ends.
71          .onActionEnd((event: GestureEvent) => {
72            this.count = 0
73          })
74        )
75    }
76    .height(200)
77    .width(300)
78    .padding(20)
79    .border({ width: 3 })
80    .margin(30)
81  }
82}
83```
84
85![en-us_image_0000001174264380](figures/en-us_image_0000001174264380.gif)
86