1# SwipeGesture
2
3**SwipeGesture** is used to implement a swipe gesture, which can be recognized when the swipe speed is 100 vp/s or higher.
4
5>  **NOTE**
6>
7>  This gesture is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## APIs
11
12SwipeGesture(value?: { fingers?: number, direction?: SwipeDirection, speed?: number })
13
14**Atomic service API**: This API can be used in atomic services since API version 11.
15
16**Parameters**
17
18| Name| Type| Mandatory| Description|
19| -------- | -------- | -------- | -------- |
20| fingers | number | No| Minimum number of fingers to trigger a swipe gesture. The value ranges from 1 to 10.<br>Default value: **1**|
21| direction | [swipeDirection](#swipedirection)| No| Swipe direction.<br>Default value: **SwipeDirection.All**|
22| speed | number | No| Minimum speed of the swipe gesture.<br>Default value: 100 vp/s<br>**NOTE**<br>If the value is less than or equal to 0, it will be converted to the default value.|
23
24## SwipeDirection
25
26**Atomic service API**: This API can be used in atomic services since API version 11.
27
28| Name| Description|
29| -------- | -------- |
30| All | All directions.|
31| Horizontal | Horizontal direction. The gesture event is triggered when the angle between the finger moving direction and the x-axis is less than 45 degrees.|
32| Vertical | Vertical direction. The gesture event is triggered when the angle between the finger moving direction and the y-axis is less than 45 degrees.|
33| None | Swiping disabled.|
34
35
36## Events
37
38| Name| Description|
39| -------- | -------- |
40| onAction(event:(event: [GestureEvent](ts-gesture-settings.md#gestureevent)) =&gt; void) | Invoked when the swipe gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
41
42## Attributes
43
44| Name| Type   |Description                                       |
45| ----  | ------  | ---------------------------------------- |
46| tag<sup>11+</sup>   | string  | Tag for the swipe 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.|
47| allowedTypes<sup>14+</sup> | Array\<[SourceTool](ts-gesture-settings.md#sourcetool9)> | Allowed event input types for the swipe gesture.<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
48
49## Example
50
51This example demonstrates the recognition of a swipe gesture using **SwipeGesture**.
52
53```ts
54// xxx.ets
55@Entry
56@Component
57struct SwipeGestureExample {
58  @State rotateAngle: number = 0
59  @State speed: number = 1
60
61  build() {
62    Column() {
63      Column() {
64        Text("SwipeGesture speed\n" + this.speed)
65        Text("SwipeGesture angle\n" + this.rotateAngle)
66      }
67      .border({ width: 3 })
68      .width(300)
69      .height(200)
70      .margin(100)
71      .rotate({ angle: this.rotateAngle })
72      // The gesture event is triggered by swiping vertically with one finger.
73      .gesture(
74      SwipeGesture({ direction: SwipeDirection.Vertical })
75        .onAction((event: GestureEvent) => {
76          if (event) {
77            this.speed = event.speed
78            this.rotateAngle = event.angle
79          }
80        })
81      )
82    }.width('100%')
83  }
84}
85```
86
87 ![en-us_image_0000001231374559.png](figures/en-us_image_0000001231374559.png)
88