• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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**Atomic service API**: This API can be used in atomic services since API version 11.
45
46| Name| Type   |Description                                       |
47| ----  | ------  | ---------------------------------------- |
48| tag<sup>11+</sup>   | string  | Tag for the swipe gesture. It is used to distinguish the gesture during custom gesture judgment.|
49
50## Example
51
52```ts
53// xxx.ets
54@Entry
55@Component
56struct SwipeGestureExample {
57  @State rotateAngle: number = 0
58  @State speed: number = 1
59
60  build() {
61    Column() {
62      Column() {
63        Text("SwipeGesture speed\n" + this.speed)
64        Text("SwipeGesture angle\n" + this.rotateAngle)
65      }
66      .border({ width: 3 })
67      .width(300)
68      .height(200)
69      .margin(100)
70      .rotate({ angle: this.rotateAngle })
71      // The gesture event is triggered by swiping vertically with one finger.
72      .gesture(
73      SwipeGesture({ direction: SwipeDirection.Vertical })
74        .onAction((event: GestureEvent) => {
75          if (event) {
76            this.speed = event.speed
77            this.rotateAngle = event.angle
78          }
79        })
80      )
81    }.width('100%')
82  }
83}
84```
85
86 ![en-us_image_0000001231374559.png](figures/en-us_image_0000001231374559.png)
87