• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14**Parameters**
15
16| Name| Type| Mandatory| Description|
17| -------- | -------- | -------- | -------- |
18| fingers | number | No| Minimum number of fingers to trigger a long press gesture. The value ranges from 1 to 10.<br>Default value: **1**|
19| repeat | boolean | No| Whether to continuously trigger the event callback.<br>Default value: **false**|
20| duration | number | No| Minimum hold-down time, in ms.<br>Default value: **500**|
21
22
23## Events
24
25| Name| Description|
26| -------- | -------- |
27| onAction(event:(event?: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Invoked when a long press gesture is recognized.|
28| onActionEnd(event:(event?: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Invoked when the finger used for a long press gesture is lift.|
29| onActionCancel(event: () =&gt; void) | Invoked when a tap cancellation event is received after a long press gesture is recognized.|
30
31
32## Example
33
34```ts
35// xxx.ets
36@Entry
37@Component
38struct LongPressGestureExample {
39  @State count: number = 0
40
41  build() {
42    Column() {
43      Text('LongPress onAction:' + this.count).fontSize(28)
44        // Touch and hold the text with one finger to trigger the gesture event.
45        .gesture(
46        LongPressGesture({ repeat: true })
47          // 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).
48          .onAction((event: GestureEvent) => {
49            if (event.repeat) {
50              this.count++
51            }
52          })
53            // Triggered when the long press gesture ends.
54          .onActionEnd(() => {
55            this.count = 0
56          })
57        )
58    }
59    .height(200)
60    .width(300)
61    .padding(20)
62    .border({ width: 3 })
63    .margin(30)
64  }
65}
66```
67
68![en-us_image_0000001257058425](figures/en-us_image_0000001257058425.gif)
69