• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TapGesture
2
3**TapGesture** is used to trigger a tap gesture with one, two, or more taps.
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
12TapGesture(value?: { count?: number, fingers?: number })
13
14**Parameters**
15
16| Name| Type| Mandatory| Description|
17| -------- | -------- | -------- | -------- |
18| count | number | No| Number of consecutive taps. If the value is less than 1 or is not set, the default value is used.<br>Default value: **1**<br>**NOTE**<br>If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms.|
19| fingers | number | No| Number of fingers required to trigger a tap. The value ranges from 1 to 10. If the value is less than 1 or is not set, the default value is used.<br>Default value: **1**<br>**NOTE**<br>1. If the value is greater than 1, the tap gesture will fail to be recognized when the number of fingers touching the screen within 300 ms of the first finger touch is less than the required number.<br>2. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized.|
20
21
22## Events
23
24| Name| Description|
25| -------- | -------- |
26| onAction(event: (event?: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Callback invoked when a tap gesture is recognized.|
27
28
29## Example
30
31```ts
32// xxx.ets
33@Entry
34@Component
35struct TapGestureExample {
36  @State value: string = ''
37
38  build() {
39    Column() {
40      // The gesture event is triggered by double-tapping.
41      Text('Click twice').fontSize(28)
42        .gesture(
43        TapGesture({ count: 2 })
44          .onAction((event?: GestureEvent) => {
45            if (event) {
46              this.value = JSON.stringify(event.fingerList[0])
47            }
48          })
49        )
50      Text(this.value)
51    }
52    .height(200)
53    .width(300)
54    .padding(20)
55    .border({ width: 3 })
56    .margin(30)
57  }
58}
59```
60
61![en-us_image_0000001256858417](figures/en-us_image_0000001256858417.gif)
62