Gesture Common APIs
Provides common APIs related to gestures.
NOTE
The initial APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
GestureInterface<T>11+
Defines the gesture API.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
tag11+
tag(tag: string): T
Sets a gesture tag.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| tag | string | Yes | Gesture tag. |
Return value
| Type | Description |
|---|---|
| T | Current component. |
allowedTypes14+
allowedTypes(types: Array<SourceTool>): T
Sets the input types that can trigger the gesture response.
Atomic service API: This API can be used in atomic services since API version 14.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| types | Array<SourceTool> | Yes | Input types that can trigger the gesture response. |
Return value
| Type | Description |
|---|---|
| T | Current component. |
ScrollableTargetInfo12+
Provides the information about the scrollable container component corresponding to the gesture recognizer. It inherits from EventTargetInfo.
isBegin12+
isBegin(): boolean
Checks whether this scrollable container component is scrolled to the top. If it is a Swiper component in loop mode, false is returned.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Whether the current scrollable container component is scrolled to the top. The value true means that the component is scrolled to the top, and false means the opposite. |
isEnd12+
isEnd(): boolean
Checks whether the current scroll container is scrolled to the bottom. If the container is a Swiper component and is in loop mode, false is returned.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Whether the current scrollable container component is scrolled to the bottom. The value true means that the component is scrolled to the bottom, and false means the opposite. |
EventTargetInfo12+
Provides the information about the component corresponding to the gesture recognizer.
getId12+
getId(): string
Obtains the ID of this component.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| string | ID of the current component. |
TouchRecognizer20+
Represents a touch gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.ArkUI.ArkUI.Full
getEventTargetInfo20+
getEventTargetInfo(): EventTargetInfo
Obtains the information about the component corresponding to this touch gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| EventTargetInfo | Information about the component corresponding to the current touch gesture recognizer. |
cancelTouch20+
cancelTouch(): void
Sends a touch cancellation event to this touch gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.ArkUI.ArkUI.Full
GestureRecognizer12+
Gesture recognizer object.
getTag12+
getTag(): string
Obtains the tag of this gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| string | Tag of the current gesture recognizer. |
getType12+
getType(): GestureControl.GestureType
Obtains the type of this gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| GestureControl.GestureType | Type of the current gesture recognizer. |
isBuiltIn12+
isBuiltIn(): boolean
Obtains whether this gesture recognizer is a built-in gesture.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Whether the current gesture recognizer is a built-in gesture. The value true means that the gesture recognizer is a built-in gesture, and false means the opposite. |
setEnabled12+
setEnabled(isEnabled: boolean): void
Sets the enabled state of this gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| isEnabled | boolean | Yes | Enabled state to set. The value true means that the gesture recognizer is enabled and will trigger events, and false means the opposite. |
isEnabled12+
isEnabled(): boolean
Obtains the enabled state of this gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Enabled state of the gesture recognizer. The value true means that the gesture recognizer is enabled and will trigger events, and false means the opposite. |
getState12+
getState(): GestureRecognizerState
Obtains the state of this gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| GestureRecognizerState | State of the gesture recognizer. |
getEventTargetInfo12+
getEventTargetInfo(): EventTargetInfo
Obtains the information about the component corresponding to this gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| EventTargetInfo | Information about the component corresponding to the current gesture recognizer. |
isValid12+
isValid(): boolean;
Whether the current gesture recognizer is valid.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Whether the current gesture recognizer is valid. Returns false if the component bound to this recognizer is destroyed or if the recognizer is not on the response chain. Returns true if the bound component exists and the recognizer is in the response chain. |
getFingerCount18+
getFingerCount(): number
Obtains the number of fingers required to trigger the preset gesture.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Number of fingers required to trigger the preset gesture. Value range: an integer from 1 to 10. |
isFingerCountLimit18+
isFingerCountLimit(): boolean
Checks whether the preset gesture detects the number of fingers on the screen.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Whether the preset gesture will detect the number of fingers on the screen. true if the gesture event is bound and detects the number of fingers; false otherwise. |
preventBegin20+
preventBegin(): void
Prevents a gesture recognizer from participating in the current gesture recognition before all fingers are lifted. If the system has already determined the result of the gesture recognizer (regardless of success or failure), calling this API will be ineffective. Unlike GestureRecognizer.setEnabled(isEnabled: boolean), which only affects callback execution, this API prevents the recognizer from participating in the recognition process entirely.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.ArkUI.ArkUI.Full
TapRecognizer18+
Implements a tap gesture recognizer object. Inherits from GestureRecognizer.
getTapCount18+
getTapCount(): number
Obtains the number of consecutive taps required for the tap gesture to be recognized.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Number of consecutive taps required for the tap gesture to be recognized. Value range: [0, +∞) |
LongPressRecognizer18+
Implements a long press gesture recognizer. Inherits from GestureRecognizer.
isRepeat18+
isRepeat(): boolean
Checks whether the long press gesture recognizer is set to trigger repeated callbacks.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| boolean | Whether the long press gesture recognizer is set to trigger repeated callbacks. false: Repeated callbacks are not triggered. true: Repeated callbacks are triggered. |
getDuration18+
getDuration(): number
Obtains the minimum duration required for the long press gesture to be recognized.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Minimum duration, in ms. Value range: [0, +∞) |
getAllowableMovement22+
getAllowableMovement(): number
Obtains the maximum movement distance allowed for gesture recognition by the long press gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 22.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Maximum movement distance recognized by the long press gesture recognizer, in px. Value range: (0, +∞) |
SwipeRecognizer18+
Implements a swipe gesture recognizer. Inherits from GestureRecognizer.
getVelocityThreshold18+
getVelocityThreshold(): number
Obtains the minimum velocity required for the swipe gesture to be recognized.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Minimum velocity required for the swipe gesture to be recognized, in vp/s. Value range: [0, +∞) |
getDirection18+
getDirection(): SwipeDirection
Obtains the direction for recognizing swipe gestures.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| SwipeDirection | Direction for recognizing swipe gestures. |
PinchRecognizer18+
Implements a pinch gesture recognizer. Inherits from GestureRecognizer.
getDistance18+
getDistance(): number
Obtains the minimum distance required for the pinch gesture to be recognized.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Minimum distance required for the pinch gesture to be recognized, in vp. Value range: [0, +∞) |
RotationRecognizer18+
Implements a rotation gesture recognizer. Inherits from GestureRecognizer.
getAngle18+
getAngle(): number
Obtains the minimum angle change required for the rotation gesture to be recognized.
Atomic service API: This API can be used in atomic services since API version 18.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Minimum angle change required for the rotation gesture to be recognized, in degrees (deg). Value range: [0, +∞) NOTE If the provided angle is less than or equal to 0 or greater than 360, it is converted to the default value 1. |
PanRecognizer12+
Implements a pan gesture recognizer. Inherits from GestureRecognizer.
getPanGestureOptions12+
getPanGestureOptions(): PanGestureOptions
Obtains the properties of this pan gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| PanGestureOptions | Properties of the current pan gesture recognizer. |
getDirection19+
getDirection(): PanDirection
Obtains the recognized direction of the current pan gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 19.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| PanDirection | Recognized direction of the current pan gesture recognizer. |
getDistance19+
getDistance(): number
Obtains the minimum pan distance required to trigger this pan gesture recognizer.
Atomic service API: This API can be used in atomic services since API version 19.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Minimum swipe distance. Unit: vp. |
getDistanceMap19+
getDistanceMap(): Map<SourceTool, number>
Obtains the minimum pan distances required for different input sources to trigger this pan gesture recognizer.
NOTE
This API only returns thresholds for input sources that have been explicitly configured during pan gesture initialization. The default threshold can be queried using the SourceTool.Unknown type. Thresholds for unconfigured device types are not available.
Atomic service API: This API can be used in atomic services since API version 19.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| Map<SourceTool, number> | Minimum pan distances required for different input sources to trigger the pan gesture recognizer. Unit: vp. |
GestureRecognizerState12+
Enumerates the gesture recognizer states.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| READY | 0 | Ready. |
| DETECTING | 1 | Detecting. |
| PENDING | 2 | Pending. |
| BLOCKED | 3 | Blocked. |
| SUCCESSFUL | 4 | Successful. |
| FAILED | 5 | Failed. |
GestureEvent
Defines the gesture event information. Inherits from BaseEvent.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| repeat | boolean | No | No | Whether the event is a repeated trigger event, used in the LongPressGesture scenarios. The value true means that the event is a repeated trigger event, and false means the opposite. Atomic service API: This API can be used in atomic services since API version 11. |
| offsetX | number | No | No | X-axis offset of the gesture event relative to the finger press position, in vp. Used in PanGesture scenarios. A positive value means to pan from left to right, and a negative value means the opposite. Atomic service API: This API can be used in atomic services since API version 11. Value range: (-∞, +∞) |
| offsetY | number | No | No | Y-axis offset of the gesture event relative to the finger press position, in vp. Used in PanGesture scenarios. A positive value means to pan from top to bottom, and a negative value means the opposite. Atomic service API: This API can be used in atomic services since API version 11. Value range: (-∞, +∞) |
| angle | number | No | No | Rotation angle for the RotationGesture event. Angle of the swipe gesture for the SwipeGesture event, that is, the change in the included angle between the line segment created by the two fingers and the horizontal direction. NOTE 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. Value range: [-180, +180] Atomic service API: This API can be used in atomic services since API version 11. |
| scale | number | No | No | Scale ratio. This attribute is used for the pinch gesture. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| pinchCenterX | number | No | No | X-coordinate of the center of the pinch gesture, in vp, relative to the original area of the current component. This attribute is used for the PinchGesture event. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| pinchCenterY | number | No | No | Y-coordinate of the center of the pinch gesture, in vp, relative to the original area of the current component. This attribute is used for the PinchGesture event. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| speed8+ | number | No | No | Swipe gesture speed, that is, the average swipe speed of all fingers relative to the original area of the current component, in vp/s. Used for the SwipeGesture event. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| fingerList8+ | FingerInfo[] | No | No | List of touch points of the gesture event. If the event input device is touchscreen, the list includes all touch points. If the event input device is mouse or touchpad, the list contains only one touch point. NOTE 1. The index of a finger corresponds to its position, that is, the ID of a finger in fingerList[index] refers to its index. If a finger is pressed first and does not participate in triggering of the current gesture, its position in fingerList is left empty. 2. fingerList is empty when gestures are triggered using a keyboard or game controller and no finger information exists. Atomic service API: This API can be used in atomic services since API version 11. |
| fingerInfos20+ | FingerInfo[] | No | Yes | Information about touch points of the gesture event. For gesture events initiated by a touchscreen, fingerInfos includes information about all touch points. For gesture events initiated by a mouse or touchpad, fingerInfos contains only one touch point. NOTE fingerInfos only records information about effective fingers that participate in the touch. Fingers that are pressed first but do not participate in triggering of the current gesture will not be shown in fingerInfos. The default value is an empty array [], and an empty array indicates no effective touch point information. Atomic service API: This API can be used in atomic services since API version 20. |
| velocityX10+ | number | No | No | Velocity along the x-axis. This parameter is used in PanGesture. 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. Value range: (-∞, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| velocityY10+ | number | No | No | Velocity along the y-axis. This parameter is used in PanGesture. 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. Value range: (-∞, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| velocity10+ | number | No | No | Velocity along the main axis. This parameter is used in PanGesture. 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. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| tapLocation20+ | EventLocationInfo | No | Yes | Coordinate information of the current tap gesture. For non-tap gestures, the return value of tapLocation is undefined. Atomic service API: This API can be used in atomic services since API version 20. |
GestureMask
Enumerates masking modes of child component gestures.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| Normal | - | The gestures of child components are enabled and recognized based on the default gesture recognition sequence. |
| IgnoreInternal | - | The gestures of child components are disabled, including the built-in gestures, such as the built-in swipe gesture for a List component. If the areas of the parent and child components are partly overlapped, only gestures in the overlapped areas are disabled. |
GestureJudgeResult11+
Enumerates gesture competition results.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| CONTINUE | 0 | The system gesture recognition process continues. |
| REJECT | 1 | Gesture recognition fails. |
GestureType11+
Enumerates gesture recognizer types.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Value | Description |
|---|---|---|
| TAP_GESTURE | 0 | Tap. Atomic service API: This API can be used in atomic services since API version 12. |
| LONG_PRESS_GESTURE | 1 | Long press gesture. Atomic service API: This API can be used in atomic services since API version 12. |
| PAN_GESTURE | 2 | Pan. Atomic service API: This API can be used in atomic services since API version 12. |
| PINCH_GESTURE | 3 | Pinch gesture. Atomic service API: This API can be used in atomic services since API version 12. |
| SWIPE_GESTURE | 4 | Swipe. Atomic service API: This API can be used in atomic services since API version 12. |
| ROTATION_GESTURE | 5 | Rotation gesture. Atomic service API: This API can be used in atomic services since API version 12. |
| DRAG | 6 | Drag and drop. Atomic service API: This API can be used in atomic services since API version 12. |
| CLICK | 7 | Click. Atomic service API: This API can be used in atomic services since API version 12. |
| BOX_SELECT_GESTURE23+ | 8 | Swipe gesture used to create a selection area by dragging with the mouse within a scroll container, enabling the batch selection of multiple elements. Model restriction: This API can be used only in the stage model. Atomic service API: This API can be used in atomic services since API version 23. |
| WEB_SCROLL_GESTURE23+ | 9 | Swipe gesture used to control the scrolling behavior of a Web component. Model restriction: This API can be used only in the stage model. Atomic service API: This API can be used in atomic services since API version 23. |
| TEXT_FIELD_SELECT_GESTURE23+ | 10 | Swipe gesture used to select text content by dragging within an input box component. Model restriction: This API can be used only in the stage model. Atomic service API: This API can be used in atomic services since API version 23. |
| CONTEXT_MENU_HOVER_GESTURE23+ | 11 | Context menu hover gesture. It is a special type of long-press gesture and triggers the hoverScale animation effect of the menu during the long-press process (this behavior requires enabling the hoverScaleInterruption attribute of ContextMenuAnimationOptions for support). Model restriction: This API can be used only in the stage model. Atomic service API: This API can be used in atomic services since API version 23. |
GestureInfo11+
Defines the gesture information type.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| tag | string | No | Yes | Gesture tag. NOTE Returns undefined if the gesture's tag attribute was not set. |
| type | GestureControl.GestureType | No | No | Gesture type. NOTE Returns -1 for built-in gestures of unexposed types. |
| isSystemGesture | boolean | No | No | Whether the gesture is a system/component gesture. true if the gesture is a system/component gesture, false otherwise. Default value: false |
FingerInfo8+
Defines the finger information type.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| id | number | No | No | Index of the finger, determined by the number of fingers pressed. The first pressed finger is assigned 0, with the index incrementing by one for each subsequent finger. NOTE Indexes for other input sources (mouse: 1001, stylus: 102, mouse wheel: 0, two-finger trackpad slide: 0) are also converted to finger indexes. Value range: [0, 9) Atomic service API: This API can be used in atomic services since API version 11. |
| globalX | number | No | No | X-coordinate relative to the upper left corner of the application window, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| globalY | number | No | No | Y-coordinate relative to the upper left corner of the application window, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| localX | number | No | No | X-coordinate relative to the upper left corner of the current component's original area, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| localY | number | No | No | Y-coordinate relative to the upper left corner of the current component's original area, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 11. |
| displayX12+ | number | No | No | X-coordinate relative to the upper left corner of the screen, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 12. |
| displayY12+ | number | No | No | Y-coordinate relative to the upper left corner of the screen, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 12. |
| hand15+ | InteractionHand | No | Yes | Whether the event is triggered by a left-hand or right-hand tap. Atomic service API: This API can be used in atomic services since API version 15. |
| globalDisplayX20+ | number | No | Yes | X-coordinate relative to the upper left corner of the global display, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 20. |
| globalDisplayY20+ | number | No | Yes | Y-coordinate relative to the upper left corner of the global display, in vp. Value range: [0, +∞) Atomic service API: This API can be used in atomic services since API version 20. |
GestureType
type GestureType = TapGesture|LongPressGesture|PanGesture|PinchGesture|SwipeGesture|RotationGesture|GestureGroup
Enumerates gesture recognizer types. The value type is a union of the types listed in the table below.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Type | Description |
|---|---|
| TapGesture | Tap gesture, which can be a single-tap or multi-tap gesture. |
| LongPressGesture | Long press. |
| PanGesture | Pan gesture (triggered when the movement distance of a finger on the screen reaches the minimum value, which is 5 vp by default). |
| PinchGesture | Pinch gesture. |
| RotationGesture | Rotation gesture. |
| SwipeGesture | Swipe gesture (triggered when the swipe speed exceeds the specified threshold, which is 100 vp/s by default). |
| GestureGroup | A group of gestures. Continuous recognition, parallel recognition, and exclusive recognition are supported. |
BaseGestureEvent11+
Defines the basic gesture event type. Inherits from BaseEvent.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| fingerList | FingerInfo[] | No | No | Information about all fingers triggering the event. Atomic service API: This API can be used in atomic services since API version 12. |
| fingerInfos20+ | FingerInfo[] | No | Yes | Information about all valid touch points. The default value is an empty array [], and an empty array indicates no effective touch point information. Atomic service API: This API can be used in atomic services since API version 20. |
TapGestureEvent11+
Inherits from BaseGestureEvent. This object can be passed as the event parameter of onGestureJudgeBegin.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| tapLocation20+ | EventLocationInfo | No | Yes | Coordinates of the tap gesture. Atomic service API: This API can be used in atomic services since API version 20. |
LongPressGestureEvent11+
Inherits from BaseGestureEvent. This object can be passed as the event parameter of onGestureJudgeBegin.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| repeat | boolean | No | No | Whether the event is a repeated trigger event. true: The event is repeated. false: The event is not repeated. |
PanGestureEvent11+
Inherits from BaseGestureEvent. This object can be passed as the event parameter of onGestureJudgeBegin.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| offsetX | number | No | No | 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. |
| offsetY | number | No | No | 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. |
| velocityX | number | No | No | 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. |
| velocityY | number | No | No | 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. |
| velocity | number | No | No | 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. |
PinchGestureEvent11+
Inherits from BaseGestureEvent. This object can be passed as the event parameter of onGestureJudgeBegin.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| scale | number | No | No | Scale factor. |
| pinchCenterX | number | No | No | X-coordinate of the center of the pinch gesture, in vp, relative to the original area of the current component. |
| pinchCenterY | number | No | No | Y-coordinate of the center of the pinch gesture, in vp, relative to the original area of the current component. |
RotationGestureEvent11+
Inherits from BaseGestureEvent. This object can be passed as the event parameter of onGestureJudgeBegin.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| angle | number | No | No | Rotation angle, in deg. NOTE Angle calculation: Once a rotation gesture is detected, the line connecting two fingers is considered the start line. As the fingers move, the line between them rotates. Based on the coordinates of the start line and the current line, the included angle relative to the horizontal axis is computed using the arctangent function. The final angle is calculated as follows: arctan2(cy2 - cy1, cx2 - cx1) - arctan2(y2 - y1, x2 - x1). If the start line is taken as the reference axis, clockwise rotation produces values from 0 to 180 degrees, and counterclockwise rotation produces values from –180 to 0 degrees. |
SwipeGestureEvent11+
Inherits from BaseGestureEvent. This object can be passed as the event parameter of onGestureJudgeBegin.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| angle | number | No | No | 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. NOTE Angle calculation: Once a swipe gesture is detected, the line connecting two fingers is considered the start line. As the fingers move, the line between them rotates. Based on the coordinates of the start line and the current line, the included angle relative to the horizontal axis is computed using the arctangent function. The final angle is calculated as follows: arctan2(cy2 - cy1, cx2 - cx1) - arctan2(y2 - y1, x2 - x1). If the start line is taken as the reference axis, clockwise rotation produces values from 0 to 180 degrees, and counterclockwise rotation produces values from –180 to 0 degrees. |
| speed | number | No | No | Swipe gesture speed, defined as the average swipe speed of all fingers relative to the original area of the current component. The unit is vp/s. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 ts-drawing-components-shape
openharmony 鸿蒙 ts-universal-attributes-sharp-clipping
openharmony 鸿蒙 ts-universal-attributes-toolbar
openharmony 鸿蒙 ts-container-lazyvgridlayout
openharmony 鸿蒙 ohos-arkui-advanced-FoldSplitContainer
openharmony 鸿蒙 ts-methods-calendarpicker-dialog
openharmony 鸿蒙 ts-uicommonevent
openharmony 鸿蒙 ts-basic-gestures-tapgesture