1e41f4b71Sopenharmony_ci# PanGesture 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci**PanGesture** is used to trigger a pan gesture when the movement distance of a finger on the screen reaches the minimum value. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## APIs 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciPanGesture(value?: { fingers?: number, direction?: PanDirection, distance?: number } | [PanGestureOptions](#pangestureoptions)) 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci**Parameters** 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 19e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 20e41f4b71Sopenharmony_ci| fingers | number | No | Minimum number of fingers to trigger a pan gesture. The value ranges from 1 to 10.<br>Default value: **1**<br>Value range: 1 to 10<br>**NOTE**<br>If the value is less than 1 or is not set, the default value is used. | 21e41f4b71Sopenharmony_ci| direction | [PanDirection](#pandirection) | No | Pan direction. The enumerated value supports the AND (&) and OR (\|) operations.<br>Default value: **PanDirection.All** | 22e41f4b71Sopenharmony_ci| distance | number | No | Minimum pan distance to trigger the gesture, in vp.<br>Default value: **5**<br>**NOTE**<br>If a pan gesture and [tab](ts-container-tabs.md) swipe occur at the same time, set **distance** to **1** so that the gesture can be more easily recognized.<br>If the value specified is less than **0**, the default value **5** is used. | 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci## PanDirection 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciEnumerates the pan directions. Unlike **SwipeDirection**, **PanDirection** does not have any angle restrictions. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci| Name | Description | 31e41f4b71Sopenharmony_ci| -------- | -------- | 32e41f4b71Sopenharmony_ci| All | All directions. | 33e41f4b71Sopenharmony_ci| Horizontal | Horizontal panning. | 34e41f4b71Sopenharmony_ci| Vertical | Vertical panning. | 35e41f4b71Sopenharmony_ci| Left | Panning to the left. | 36e41f4b71Sopenharmony_ci| Right | Panning to the right. | 37e41f4b71Sopenharmony_ci| Up | Panning up. | 38e41f4b71Sopenharmony_ci| Down | Panning down. | 39e41f4b71Sopenharmony_ci| None | Panning disabled. | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci## PanGestureOptions 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciThe attributes of the pan gesture recognizer can be dynamically modified using the **PanGestureOptions** API. This avoids modifying attributes through state variables, which will cause a UI re-render. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciPanGestureOptions(value?: { fingers?: number, direction?: PanDirection, distance?: number }) 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**Parameters** 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 53e41f4b71Sopenharmony_ci| --------- | ------------------------------------- | ---- | ------------------------------------------------------------ | 54e41f4b71Sopenharmony_ci| fingers | number | No | Minimum number of fingers to trigger a pan gesture. The value ranges from 1 to 10.<br>Default value: **1** | 55e41f4b71Sopenharmony_ci| direction | [PanDirection](#pandirection) | No | Pan direction. The enumerated value supports the AND (&) and OR (\|) operations.<br>Default value: **PanDirection.All** | 56e41f4b71Sopenharmony_ci| distance | number | No | Minimum pan distance to trigger the gesture, in vp.<br>Default value: **5**<br>**NOTE**<br>If a pan gesture and [tab](ts-container-tabs.md) swipe occur at the same time, set **distance** to **1** so that the gesture can be more easily recognized.<br>If the value specified is less than **0**, the default value **5** is used.<br>To avoid slow response and lagging during scrolling, set a reasonable pan distance.| 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**APIs** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| Name | Description | 61e41f4b71Sopenharmony_ci| -------- | -------- | 62e41f4b71Sopenharmony_ci| setDirection(value: [PanDirection](#pandirection)) | Sets the direction.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 63e41f4b71Sopenharmony_ci| setDistance(value: number) | Sets the distance.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 64e41f4b71Sopenharmony_ci| setFingers(value: number) | Sets the number of fingers.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 65e41f4b71Sopenharmony_ci| getDirection()<sup>12+</sup>: [PanDirection](#pandirection) | Obtains the direction.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci## Events 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci| Name | Description | 71e41f4b71Sopenharmony_ci| -------- | -------- | 72e41f4b71Sopenharmony_ci| onActionStart(event: (event: [GestureEvent](ts-gesture-settings.md#gestureevent)) => void) | Invoked when a pan gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 73e41f4b71Sopenharmony_ci| onActionUpdate(event: (event: [GestureEvent](ts-gesture-settings.md#gestureevent)) => void) | Invoked when the pan gesture status is updated.<br>If **fingerList** contains multiple fingers, this callback updates the location information of only one finger each time.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 74e41f4b71Sopenharmony_ci| onActionEnd(event: (event: [GestureEvent](ts-gesture-settings.md#gestureevent)) => void) | Invoked when the finger used for a pan gesture is lifted.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 75e41f4b71Sopenharmony_ci| onActionCancel(event: () => void) | Invoked when a tap cancellation event is received after a pan gesture is recognized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci## Attributes 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci| Name | Type |Description | 82e41f4b71Sopenharmony_ci| ---- | ------ | ---------------------------------------- | 83e41f4b71Sopenharmony_ci| tag<sup>11+</sup> | string | Tag for the pan gesture. It is used to distinguish the gesture during custom gesture judgment.| 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci## Example 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci```ts 88e41f4b71Sopenharmony_ci// xxx.ets 89e41f4b71Sopenharmony_ci@Entry 90e41f4b71Sopenharmony_ci@Component 91e41f4b71Sopenharmony_cistruct PanGestureExample { 92e41f4b71Sopenharmony_ci @State offsetX: number = 0 93e41f4b71Sopenharmony_ci @State offsetY: number = 0 94e41f4b71Sopenharmony_ci @State positionX: number = 0 95e41f4b71Sopenharmony_ci @State positionY: number = 0 96e41f4b71Sopenharmony_ci private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Left | PanDirection.Right }) 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci build() { 99e41f4b71Sopenharmony_ci Column() { 100e41f4b71Sopenharmony_ci Column() { 101e41f4b71Sopenharmony_ci Text('PanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) 102e41f4b71Sopenharmony_ci } 103e41f4b71Sopenharmony_ci .height(200) 104e41f4b71Sopenharmony_ci .width(300) 105e41f4b71Sopenharmony_ci .padding(20) 106e41f4b71Sopenharmony_ci .border({ width: 3 }) 107e41f4b71Sopenharmony_ci .margin(50) 108e41f4b71Sopenharmony_ci .translate({ x: this.offsetX, y: this.offsetY, z: 0}) // Move the component with its upper left corner as the coordinate origin. 109e41f4b71Sopenharmony_ci // Pan left or right to trigger the gesture event. 110e41f4b71Sopenharmony_ci .gesture( 111e41f4b71Sopenharmony_ci PanGesture(this.panOption) 112e41f4b71Sopenharmony_ci .onActionStart((event: GestureEvent) => { 113e41f4b71Sopenharmony_ci console.info('Pan start') 114e41f4b71Sopenharmony_ci }) 115e41f4b71Sopenharmony_ci .onActionUpdate((event: GestureEvent) => { 116e41f4b71Sopenharmony_ci if (event) { 117e41f4b71Sopenharmony_ci this.offsetX = this.positionX + event.offsetX 118e41f4b71Sopenharmony_ci this.offsetY = this.positionY + event.offsetY 119e41f4b71Sopenharmony_ci } 120e41f4b71Sopenharmony_ci }) 121e41f4b71Sopenharmony_ci .onActionEnd((event: GestureEvent) => { 122e41f4b71Sopenharmony_ci this.positionX = this.offsetX 123e41f4b71Sopenharmony_ci this.positionY = this.offsetY 124e41f4b71Sopenharmony_ci console.info('Pan end') 125e41f4b71Sopenharmony_ci }) 126e41f4b71Sopenharmony_ci ) 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci Button ('Set PanGesture Trigger Condition') 129e41f4b71Sopenharmony_ci .onClick(() => { 130e41f4b71Sopenharmony_ci // Set the pan gesture to be triggered by two fingers moving in any direction. 131e41f4b71Sopenharmony_ci this.panOption.setDirection(PanDirection.All) 132e41f4b71Sopenharmony_ci this.panOption.setFingers(2) 133e41f4b71Sopenharmony_ci }) 134e41f4b71Sopenharmony_ci } 135e41f4b71Sopenharmony_ci } 136e41f4b71Sopenharmony_ci} 137e41f4b71Sopenharmony_ci``` 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**Diagrams** 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ciPanning to the left: 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciClick **Set PanGesture Trigger Condition** to set the pan gesture to be triggered by two fingers moving toward the lower left corner. 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci  148