1# Combined Gestures 2 3Continuous recognition, parallel recognition, and exclusive recognition are supported for a group of gestures. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8 9## APIs 10 11GestureGroup(mode: GestureMode, ...gesture: GestureType[]) 12 13**Parameters** 14 15| Name | Type | Mandatory| Description | 16| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 17| mode | [GestureMode](#gesturemode) | Yes | Recognition mode of combined gestures.<br>Default value: **GestureMode.Sequence** | 18| gesture | [TapGesture](ts-basic-gestures-tapgesture.md)<br>\| [LongPressGesture](ts-basic-gestures-longpressgesture.md)<br>\| [PanGesture](ts-basic-gestures-pangesture.md)<br>\| [PinchGesture](ts-basic-gestures-pinchgesture.md)<br>\| [RotationGesture](ts-basic-gestures-rotationgesture.md)<br>\| [SwipeGesture](ts-basic-gestures-swipegesture.md)<br>\| [GestureGroup](#combined-gestures) | No | One or more basic gestures to be recognized simultaneously. If this parameter is left empty, simultaneous recognition will not take effect.<br>**NOTE**<br>To add both tap and double-tap gestures for a component, add two TapGestures, with the tap gesture added after the double-tap gesture.| 19 20## GestureMode 21 22| Name | Description | 23| --------- | ---------------------------------------- | 24| Sequence | Sequential recognition: Gestures are recognized in the registration sequence until all gestures are recognized successfully. Once one gesture fails to be recognized, all subsequent gestures fail to be recognized.<br>Only the last gesture in the sequential recognition gesture group can respond to **onActionEnd**.| 25| Parallel | Parallel recognition. Registered gestures are recognized concurrently until all gestures are recognized. The recognition result of each gesture does not affect each other. | 26| Exclusive | Exclusive recognition. Registered gestures are identified concurrently. If one gesture is successfully recognized, gesture recognition ends. | 27 28 29## Events 30 31| Name | Description | 32| ---------------------------------------- | ------------------------------------ | 33| onCancel(event: () => void) | Callback for the GestureMode.Sequence cancellation event.<br>**NOTE**<br>This event is triggered when the window loses focus.| 34 35 36## Example 37 38```ts 39// xxx.ets 40@Entry 41@Component 42struct GestureGroupExample { 43 @State count: number = 0 44 @State offsetX: number = 0 45 @State offsetY: number = 0 46 @State positionX: number = 0 47 @State positionY: number = 0 48 @State borderStyles: BorderStyle = BorderStyle.Solid 49 50 build() { 51 Column() { 52 Text('sequence gesture\n' + 'LongPress onAction:' + this.count + '\nPanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) 53 .fontSize(15) 54 } 55 .translate({ x: this.offsetX, y: this.offsetY, z: 0 }) 56 .height(150) 57 .width(200) 58 .padding(20) 59 .margin(20) 60 .border({ width: 3, style: this.borderStyles }) 61 .gesture( 62 // The following combined gestures are recognized in sequential recognition mode. If the long press gesture event is not triggered correctly, the drag gesture event will not be triggered. 63 GestureGroup(GestureMode.Sequence, 64 LongPressGesture({ repeat: true }) 65 .onAction((event?: GestureEvent) => { 66 if (event && event.repeat) { 67 this.count++ 68 } 69 console.info('LongPress onAction') 70 }), 71 PanGesture() 72 .onActionStart(() => { 73 this.borderStyles = BorderStyle.Dashed 74 console.info('pan start') 75 }) 76 .onActionUpdate((event?: GestureEvent) => { 77 if (event) { 78 this.offsetX = this.positionX + event.offsetX 79 this.offsetY = this.positionY + event.offsetY 80 } 81 console.info('pan update') 82 }) 83 .onActionEnd(() => { 84 this.positionX = this.offsetX 85 this.positionY = this.offsetY 86 this.borderStyles = BorderStyle.Solid 87 console.info('pan end') 88 }) 89 ) 90 .onCancel(() => { 91 console.info('sequence gesture canceled') 92 }) 93 ) 94 } 95} 96``` 97 98Diagram: 99 100In sequence recognition mode the long press gesture event is triggered first. 101 102 103 104After the long press gesture is recognized, the drag gesture event is triggered. 105 106  107