1e41f4b71Sopenharmony_ci# Custom Gesture Judgment 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciYou can use the custom gesture judgment APIs to specify whether to respond to specific gestures when they are being recognized. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This feature is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## onGestureJudgeBegin 11e41f4b71Sopenharmony_cionGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): T 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci**Parameters** 16e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 17e41f4b71Sopenharmony_ci| ---------- | -------------------------- | ------- | ----------------------------- | 18e41f4b71Sopenharmony_ci| callback | (gestureInfo: [GestureInfo](#gestureinfo), event: [BaseGestureEvent](#basegestureevent)) => [GestureJudgeResult](#gesturejudgeresult11) | Yes | Callback for custom gesture judgment. When the gesture bound to the component is accepted, the defined callback is triggered to obtain the result.| 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**Return value** 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci| Type| Description| 23e41f4b71Sopenharmony_ci| -------- | -------- | 24e41f4b71Sopenharmony_ci| T | Current component.| 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## GestureJudgeResult<sup>11+</sup> 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| Name | Description | 34e41f4b71Sopenharmony_ci| ----- | -------------------------------------- | 35e41f4b71Sopenharmony_ci| CONTINUE | The system gesture recognition process continues.| 36e41f4b71Sopenharmony_ci| REJECT | Recognition of the custom gesture is determined as failed.| 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci## GestureInfo 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| Name | Type | Description | 43e41f4b71Sopenharmony_ci| --------------- | ------------------------- | -----------| 44e41f4b71Sopenharmony_ci| tag | string | Gesture tag.<br>**NOTE**<br>If the event tag is not set, **undefined** or no gesture tag is returned. | 45e41f4b71Sopenharmony_ci| type | [GestureControl.GestureType](#gesturetype11) | Gesture type.| 46e41f4b71Sopenharmony_ci| isSystemGesture | boolean | Whether the current gesture is system gesture, that is, a built-in gesture of the component.<br>Default value: **false**| 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci## GestureType<sup>11+</sup> 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci| Name | Description | 55e41f4b71Sopenharmony_ci| ----- | -------------------------------------- | 56e41f4b71Sopenharmony_ci| TAP_GESTURE | Tap gesture.| 57e41f4b71Sopenharmony_ci| LONG_PRESS_GESTURE | Long press gesture.| 58e41f4b71Sopenharmony_ci| PAN_GESTURE | Pan gesture.| 59e41f4b71Sopenharmony_ci| PINCH_GESTURE | Pinch gesture.| 60e41f4b71Sopenharmony_ci| SWIPE_GESTURE | Swipe gesture.| 61e41f4b71Sopenharmony_ci| ROTATION_GESTURE | Rotation gesture.| 62e41f4b71Sopenharmony_ci| DRAG | Drag.| 63e41f4b71Sopenharmony_ci| CLICK | Click.| 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci## BaseEvent 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci| Name | Type | Description | 69e41f4b71Sopenharmony_ci| ---------| ---------------------------------------- | -----------| 70e41f4b71Sopenharmony_ci| target | [EventTarget](ts-universal-events-click.md#eventtarget8) | Display area of the element that triggers the gesture event.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 71e41f4b71Sopenharmony_ci| timestamp| number | Timestamp of the event.<br>Unit: ns<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 72e41f4b71Sopenharmony_ci| source | [SourceType](ts-gesture-settings.md#sourcetype)| Event input device.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 73e41f4b71Sopenharmony_ci| pressure | number | Press pressure.<br>Default value: **0**<br>Value range: [0, 65535). The greater the pressure, the larger the value.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 74e41f4b71Sopenharmony_ci| tiltX | number | Angle between the projection of the stylus on the device plane and the x-axis.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 75e41f4b71Sopenharmony_ci| tiltY | number | Angle between the projection of the stylus on the device plane and the y-axis.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 76e41f4b71Sopenharmony_ci| sourceTool | [SourceTool](ts-gesture-settings.md#sourcetool9) | Event input source.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 9.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 77e41f4b71Sopenharmony_ci| axisHorizontal<sup>12+</sup> | number | Horizontal axis value.<br>**NOTE**<br>The value can only be obtained in the pan gesture initiated by mouse wheel scrolling or two-finger swipes on a touchpad.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 78e41f4b71Sopenharmony_ci| axisVertical<sup>12+</sup> | number | Vertical axis value.<br>**NOTE**<br>The value can only be obtained in the pan gesture initiated by mouse wheel scrolling or two-finger swipes on a touchpad.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 79e41f4b71Sopenharmony_ci| getModifierKeyState<sup>12+</sup> | (Array<string>) => bool | Obtains the pressed status of modifier keys. For details about the error message, see the following error codes. The following modifier keys are supported: 'Ctrl'\|'Alt'\|'Shift'\|'Fn'. This API does not work for the Fn key on an externally connected keyboard.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 80e41f4b71Sopenharmony_ci| deviceId<sup>12+</sup> | number | ID of the input device that triggers the event.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**Error codes** 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../../errorcode-universal.md). 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci| ID| Error Message| 87e41f4b71Sopenharmony_ci| ------- | -------- | 88e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. 2. Parameter verification failed. | 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci## BaseGestureEvent 91e41f4b71Sopenharmony_ciExtended from [BaseEvent](#baseevent). 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci| Name | Type | Description | 96e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | -----------| 97e41f4b71Sopenharmony_ci| fingerList | [FingerInfo[]](ts-gesture-settings.md#fingerinfo8) | Information about all fingers that trigger the event. | 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci## TapGestureEvent 100e41f4b71Sopenharmony_ciExtended from [BaseGestureEvent](#basegestureevent). This object can be passed in as the **event** parameter of [onGestureJudgeBegin](#ongesturejudgebegin). 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci## LongPressGestureEvent 105e41f4b71Sopenharmony_ciExtended from [BaseGestureEvent](#basegestureevent). This object can be passed in as the **event** parameter of [onGestureJudgeBegin](#ongesturejudgebegin). 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci| Name | Type | Description | 110e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | -----------| 111e41f4b71Sopenharmony_ci| repeat | boolean | Whether the event is triggered repeatedly. | 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci## PanGestureEvent 114e41f4b71Sopenharmony_ciExtended from [BaseGestureEvent](#basegestureevent). This object can be passed in as the **event** parameter of [onGestureJudgeBegin](#ongesturejudgebegin). 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci| Name | Type | Description | 119e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | -----------| 120e41f4b71Sopenharmony_ci| offsetX | number | Offset of the gesture event on the x-axis relative to the original area of the current component, in vp. A positive value means to pan from left to right, and a negative value means the opposite. | 121e41f4b71Sopenharmony_ci| offsetY | number | Offset of the gesture event on the y-axis relative to the original area of the current component, in vp. A positive value means to pan from top to bottom, and a negative value means the opposite. | 122e41f4b71Sopenharmony_ci| velocityX | number | Velocity along the x-axis. The origin of the coordinate axis is the upper left corner of the screen. The velocity is positive if the movement is from left to right, and it is negative if the movement is from right to left. The unit is vp/s. | 123e41f4b71Sopenharmony_ci| velocityY | number | Velocity along the y-axis. The origin of the coordinate axis is the upper left corner of the screen. The velocity is positive if the movement is from top to bottom, and it is negative if the movement is from bottom to top. The unit is vp/s.| 124e41f4b71Sopenharmony_ci| velocity | number | Velocity along the main axis. The value is the arithmetic square root of the sum of squares of the velocity along the x- and y-axis. The unit is vp/s. | 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci## PinchGestureEvent 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ciExtended from [BaseGestureEvent](#basegestureevent). This object can be passed in as the **event** parameter of [onGestureJudgeBegin](#ongesturejudgebegin). 131e41f4b71Sopenharmony_ci| Name | Type | Description | 132e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------- | -----------| 133e41f4b71Sopenharmony_ci| scale | number | Scale factor. | 134e41f4b71Sopenharmony_ci| pinchCenterX | number | X coordinate of the center of the pinch gesture, in vp, relative to the original area of the current component. | 135e41f4b71Sopenharmony_ci| pinchCenterY | number | Y coordinate of the center of the pinch gesture, in vp, relative to the original area of the current component. | 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci## RotationGestureEvent 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ciExtended from [BaseGestureEvent](#basegestureevent). This object can be passed in as the **event** parameter of [onGestureJudgeBegin](#ongesturejudgebegin). 142e41f4b71Sopenharmony_ci| Name | Type | Description | 143e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------- | -----------| 144e41f4b71Sopenharmony_ci| angle | number | Rotation angle, in deg.<br>**NOTE**<br>Angle calculation method: After a swipe gesture is recognized, a line connecting the two fingers is identified as the initial line. As the fingers swipe, the line between the fingers rotates. Based on the coordinates of the initial line's and current line's end points, the arc tangent function is used to calculate the respective included angle of the points relative to the horizontal direction by using the following formula: Rotation angle = arctan2(cy2-cy1,cx2-cx1) - arctan2(y2-y1,x2-x1). The initial line is used as the coordinate system. Values from 0 to 180 degrees represent clockwise rotation, while values from –180 to 0 degrees represent counterclockwise rotation. | 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci## SwipeGestureEvent 147e41f4b71Sopenharmony_ciExtended from [BaseGestureEvent](#basegestureevent). This object can be passed in as the **event** parameter of [onGestureJudgeBegin](#ongesturejudgebegin). 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci| Name | Type | Description | 152e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------- | -----------| 153e41f4b71Sopenharmony_ci| angle | number | Angle of the swipe gesture, that is, the change in the included angle between the line segment created by the two fingers and the horizontal direction. The unit is deg.<br>**NOTE**<br>Angle calculation method: After a swipe gesture is recognized, a line connecting the two fingers is identified as the initial line. As the fingers swipe, the line between the fingers rotates. Based on the coordinates of the initial line's and current line's end points, the arc tangent function is used to calculate the respective included angle of the points relative to the horizontal direction by using the following formula: Rotation angle = arctan2(cy2-cy1,cx2-cx1) - arctan2(y2-y1,x2-x1). The initial line is used as the coordinate system. The clockwise rotation is 0 to 180 degrees, and the counter-clockwise rotation is –180 to 0 degrees.| 154e41f4b71Sopenharmony_ci| speed | number | Swipe gesture speed, that is, the average swipe speed of all fingers relative to the original area of the current component. The unit is vp/s. | 155e41f4b71Sopenharmony_ci## Example 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci### Example 1 158e41f4b71Sopenharmony_ci```ts 159e41f4b71Sopenharmony_ci// xxx.ets 160e41f4b71Sopenharmony_ci@Entry 161e41f4b71Sopenharmony_ci@Component 162e41f4b71Sopenharmony_cistruct Index { 163e41f4b71Sopenharmony_ci @State message: string = ''; 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci build() { 166e41f4b71Sopenharmony_ci Column() { 167e41f4b71Sopenharmony_ci Row({ space: 20 }) { 168e41f4b71Sopenharmony_ci Text(this.message).width(200).height(80).backgroundColor(Color.Pink) 169e41f4b71Sopenharmony_ci .fontSize(25) 170e41f4b71Sopenharmony_ci }.margin(20) 171e41f4b71Sopenharmony_ci } 172e41f4b71Sopenharmony_ci .width('100%') 173e41f4b71Sopenharmony_ci .height(200) 174e41f4b71Sopenharmony_ci .borderWidth(2) 175e41f4b71Sopenharmony_ci .onDragStart(() => { 176e41f4b71Sopenharmony_ci this.message = 'drag' 177e41f4b71Sopenharmony_ci console.log("Drag start.") 178e41f4b71Sopenharmony_ci }) 179e41f4b71Sopenharmony_ci .gesture( 180e41f4b71Sopenharmony_ci TapGesture() 181e41f4b71Sopenharmony_ci .tag("tap1")// Tag for the tap gesture. 182e41f4b71Sopenharmony_ci .onAction(() => { 183e41f4b71Sopenharmony_ci this.message = 'tap1' 184e41f4b71Sopenharmony_ci }) 185e41f4b71Sopenharmony_ci ) 186e41f4b71Sopenharmony_ci .gesture( 187e41f4b71Sopenharmony_ci LongPressGesture() 188e41f4b71Sopenharmony_ci .tag("longPress1")// Tag for the long press gesture. 189e41f4b71Sopenharmony_ci .onAction(() => { 190e41f4b71Sopenharmony_ci this.message = 'longPress' 191e41f4b71Sopenharmony_ci }) 192e41f4b71Sopenharmony_ci ) 193e41f4b71Sopenharmony_ci .gesture( 194e41f4b71Sopenharmony_ci SwipeGesture() 195e41f4b71Sopenharmony_ci .tag("swipe1")// Tag for the swipe gesture. 196e41f4b71Sopenharmony_ci .onAction(() => { 197e41f4b71Sopenharmony_ci this.message = 'swipe1' 198e41f4b71Sopenharmony_ci }) 199e41f4b71Sopenharmony_ci ) 200e41f4b71Sopenharmony_ci .gesture( 201e41f4b71Sopenharmony_ci PanGesture() 202e41f4b71Sopenharmony_ci .tag("pan1")// Tag for the pan gesture. 203e41f4b71Sopenharmony_ci .onActionStart(() => { 204e41f4b71Sopenharmony_ci this.message = 'pan1' 205e41f4b71Sopenharmony_ci }) 206e41f4b71Sopenharmony_ci ) 207e41f4b71Sopenharmony_ci .onGestureJudgeBegin((gestureInfo: GestureInfo, event: BaseGestureEvent) => { 208e41f4b71Sopenharmony_ci // If the gesture type is a long press gesture, convert the event to a long press gesture event. 209e41f4b71Sopenharmony_ci if (gestureInfo.type == GestureControl.GestureType.LONG_PRESS_GESTURE) { 210e41f4b71Sopenharmony_ci let longPressEvent = event as LongPressGestureEvent; 211e41f4b71Sopenharmony_ci console.log("repeat " + longPressEvent.repeat) 212e41f4b71Sopenharmony_ci } 213e41f4b71Sopenharmony_ci // If the gesture type is a swipe gesture, convert the event to a swipe gesture event. 214e41f4b71Sopenharmony_ci if (gestureInfo.type == GestureControl.GestureType.SWIPE_GESTURE) { 215e41f4b71Sopenharmony_ci let swipeEvent = event as SwipeGestureEvent; 216e41f4b71Sopenharmony_ci console.log("angle " + swipeEvent.angle) 217e41f4b71Sopenharmony_ci } 218e41f4b71Sopenharmony_ci // If the gesture type is a pan gesture, convert the event to a pan gesture event. 219e41f4b71Sopenharmony_ci if (gestureInfo.type == GestureControl.GestureType.PAN_GESTURE) { 220e41f4b71Sopenharmony_ci let panEvent = event as PanGestureEvent; 221e41f4b71Sopenharmony_ci console.log("velocity " + panEvent.velocity) 222e41f4b71Sopenharmony_ci } 223e41f4b71Sopenharmony_ci // Custom criteria 224e41f4b71Sopenharmony_ci if (gestureInfo.type == GestureControl.GestureType.DRAG) { 225e41f4b71Sopenharmony_ci // If REJECT is returned, the drag gesture fails. 226e41f4b71Sopenharmony_ci return GestureJudgeResult.REJECT; 227e41f4b71Sopenharmony_ci } else if (gestureInfo.tag == 'longPress1' && event.fingerList.length > 0 && event.fingerList[0].localY < 100) { 228e41f4b71Sopenharmony_ci // If CONTINUE is returned, the system recognition result is retained. 229e41f4b71Sopenharmony_ci return GestureJudgeResult.CONTINUE; 230e41f4b71Sopenharmony_ci } 231e41f4b71Sopenharmony_ci return GestureJudgeResult.CONTINUE; 232e41f4b71Sopenharmony_ci }) 233e41f4b71Sopenharmony_ci } 234e41f4b71Sopenharmony_ci} 235e41f4b71Sopenharmony_ci``` 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci### Example 2 238e41f4b71Sopenharmony_ci```ts 239e41f4b71Sopenharmony_ci// xxx.ets 240e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI'; 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci@Entry 243e41f4b71Sopenharmony_ci@Component 244e41f4b71Sopenharmony_cistruct Index { 245e41f4b71Sopenharmony_ci scroller: Scroller = new Scroller() 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci build() { 248e41f4b71Sopenharmony_ci Scroll(this.scroller) { 249e41f4b71Sopenharmony_ci Column({ space: 8 }) { 250e41f4b71Sopenharmony_ci Text("The upper red area is bound to the long press gesture, and the lower blue area is bound to a drag gesture. If a pan is performed after a long press in the upper red area, the area only responds to the long press. In the same case, the lower blue area only responds to the drag.) .width('100%').fontSize(20).fontColor('0xffdd00') 251e41f4b71Sopenharmony_ci .backgroundColor(0xeeddaa00) 252e41f4b71Sopenharmony_ci Stack({ alignContent: Alignment.Center }) { 253e41f4b71Sopenharmony_ci Column() { 254e41f4b71Sopenharmony_ci // Simulate the upper and lower half areas. 255e41f4b71Sopenharmony_ci Stack().width('200vp').height('100vp').backgroundColor(Color.Red) 256e41f4b71Sopenharmony_ci Stack().width('200vp').height('100vp').backgroundColor(Color.Blue) 257e41f4b71Sopenharmony_ci }.width('200vp').height('200vp') 258e41f4b71Sopenharmony_ci // The lower half area of the stack is an image area bound to the pan gesture. 259e41f4b71Sopenharmony_ci Image($r('sys.media.ohos_app_icon')) 260e41f4b71Sopenharmony_ci .draggable(true) 261e41f4b71Sopenharmony_ci .onDragStart(()=>{ 262e41f4b71Sopenharmony_ci promptAction.showToast({ message: "When the blue area is dragged, the image responds" }) 263e41f4b71Sopenharmony_ci }) 264e41f4b71Sopenharmony_ci .width('200vp').height('200vp') 265e41f4b71Sopenharmony_ci // The upper half area of the stack is a floating area bound to the long press gesture. 266e41f4b71Sopenharmony_ci Stack() { 267e41f4b71Sopenharmony_ci } 268e41f4b71Sopenharmony_ci .width('200vp') 269e41f4b71Sopenharmony_ci .height('200vp') 270e41f4b71Sopenharmony_ci .hitTestBehavior(HitTestMode.Transparent) 271e41f4b71Sopenharmony_ci .onGestureJudgeBegin((gestureInfo: GestureInfo, event: BaseGestureEvent) => { 272e41f4b71Sopenharmony_ci // Check whether the tag has a value. 273e41f4b71Sopenharmony_ci if (gestureInfo.tag) { 274e41f4b71Sopenharmony_ci console.log("gestureInfo tag" + gestureInfo.tag.toString()) 275e41f4b71Sopenharmony_ci } 276e41f4b71Sopenharmony_ci console.log("gestureInfo Type " + gestureInfo.type.toString() + " isSystemGesture " + gestureInfo.isSystemGesture); 277e41f4b71Sopenharmony_ci console.log("pressure " + event.pressure + " fingerList.length " + event.fingerList.length 278e41f4b71Sopenharmony_ci + " timeStamp " + event.timestamp + " sourceType " + event.source.toString() + " titleX " + event.tiltX + " titleY " + event.tiltY + " sourcePool " + event.sourceTool.toString()); 279e41f4b71Sopenharmony_ci // If the gesture is a long press gesture, check whether the touch position is in the upper half area. 280e41f4b71Sopenharmony_ci if (gestureInfo.type == GestureControl.GestureType.LONG_PRESS_GESTURE) { 281e41f4b71Sopenharmony_ci if (event.fingerList.length > 0 && event.fingerList[0].localY < 100) { 282e41f4b71Sopenharmony_ci return GestureJudgeResult.CONTINUE 283e41f4b71Sopenharmony_ci } else { 284e41f4b71Sopenharmony_ci return GestureJudgeResult.REJECT 285e41f4b71Sopenharmony_ci } 286e41f4b71Sopenharmony_ci } 287e41f4b71Sopenharmony_ci return GestureJudgeResult.CONTINUE 288e41f4b71Sopenharmony_ci }) 289e41f4b71Sopenharmony_ci .gesture(GestureGroup(GestureMode.Parallel, 290e41f4b71Sopenharmony_ci LongPressGesture() 291e41f4b71Sopenharmony_ci .onAction((event: GestureEvent) => { 292e41f4b71Sopenharmony_ci promptAction.showToast ({ message: "When long pressed, the red area responds." }) 293e41f4b71Sopenharmony_ci }) 294e41f4b71Sopenharmony_ci .tag("tap111") 295e41f4b71Sopenharmony_ci )) 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci }.width('100%') 298e41f4b71Sopenharmony_ci }.width('100%') 299e41f4b71Sopenharmony_ci } 300e41f4b71Sopenharmony_ci } 301e41f4b71Sopenharmony_ci} 302e41f4b71Sopenharmony_ci``` 303e41f4b71Sopenharmony_ci 304