openharmony 鸿蒙 capi-arkui-nativemodule-arkui-nativegestureapi-1

2026-08-25 浏览 (1)

ArkUI_NativeGestureAPI_1

typedef struct {...} ArkUI_NativeGestureAPI_1

Overview

Defines the gesture APIs.

Since: 12

Related module: ArkUI_NativeModule

Header file: native_gesture.h

Summary

Member Variables

NameDescription
int32_t versionThe struct version is 1.

Member Functions

NameDescription
ArkUI_GestureRecognizer* (*createTapGesture)(int32_t countNum, int32_t fingersNum)Creates a tap gesture.
1. This API is used to trigger a tap gesture with one, two, or more taps.
2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms.
3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, gesture recognition fails.
4. When multiple fingers are configured for a gesture, the recognition fails if the number of fingers touching the screen within 300 ms of the initial touch is less than the required count, or if the number of fingers lifted from the screen within 300 ms of the first finger's being lifted is less than the required count.
5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized.
ArkUI_GestureRecognizer* (*createLongPressGesture)(int32_t fingersNum, bool repeatResult, int32_t durationNum)Creates a long press gesture.
1. This API is used to trigger a long press gesture, which requires one or more fingers with a minimum 500 ms hold-down time.
2. In components that support drag actions by default, such as Text, TextInput, TextArea, HyperLink, Image, and RichEditor,
the long press gesture may conflict with the drag action. If this occurs, the event priority is determined as follows:
If the minimum duration of the long press gesture is less than 500 ms, the long press gesture receives a higher response priority than the drag action.
If the minimum duration of the long press gesture is greater than or equal to 500 ms, the drag action receives a higher response priority than the long press gesture.
3. If a finger moves more than 15 px after being pressed, the gesture recognition fails.
ArkUI_GestureRecognizer* (*createPanGesture)(int32_t fingersNum, ArkUI_GestureDirectionMask directions, double distanceNum)Creates a swipe gesture.
1. This API is used to trigger a pan gesture when the movement distance of a finger on the screen exceeds the minimum value.
2. If a pan gesture and a tab swipe occur at the same time, set distanceNum to 1 so that the gesture can be more easily recognized.
ArkUI_GestureRecognizer* (*createPinchGesture)(int32_t fingersNum, double distanceNum)Creates a pinch gesture.
1. This API is used to trigger a pinch gesture, which requires two to five fingers with a minimum pinch distance of pixels specified by distanceNum.
2. While more fingers than the minimum number can be pressed to trigger the gesture, only the first fingers of the minimum number participate in gesture calculation.
ArkUI_GestureRecognizer* (*createRotationGesture)(int32_t fingersNum, double angleNum)Creates a rotation gesture.
1. This API is used to trigger a rotation gesture, which requires two to five fingers with a minimum 1-degree rotation angle.
2. While more fingers than the minimum number can be pressed to trigger the gesture, only the first two fingers participate in gesture calculation.
ArkUI_GestureRecognizer* (*createSwipeGesture)(int32_t fingersNum, ArkUI_GestureDirectionMask directions, double speedNum)Creates a swipe gesture. This API is used to implement a swipe gesture, which can be recognized when the swipe speed (px/s) is higher than that specified by speedNum.
ArkUI_GestureRecognizer* (*createGroupGesture)(ArkUI_GroupGestureMode gestureMode)Creates a gesture group.
void (*dispose)(ArkUI_GestureRecognizer* recognizer)Disposes of a gesture to release resources.
int32_t (*addChildGesture)(ArkUI_GestureRecognizer* group, ArkUI_GestureRecognizer* child)Adds a gesture to a gesture group.
int32_t (*removeChildGesture)(ArkUI_GestureRecognizer* group, ArkUI_GestureRecognizer* child)Removes a gesture from a gesture group.
int32_t (*setGestureEventTarget)(ArkUI_GestureRecognizer* recognizer, ArkUI_GestureEventActionTypeMask actionTypeMask, void* extraParams,void (*targetReceiver)(ArkUI_GestureEvent* event, void* extraParams))Registers a callback for gestures.
int32_t (*addGestureToNode)(ArkUI_NodeHandle node, ArkUI_GestureRecognizer* recognizer, ArkUI_GesturePriority mode, ArkUI_GestureMask mask)Adds a gesture to a UI component.
int32_t (*removeGestureFromNode)(ArkUI_NodeHandle node, ArkUI_GestureRecognizer* recognizer)Removes a gesture from a node.
int32_t (*setGestureInterrupterToNode)(ArkUI_NodeHandle node, ArkUI_GestureInterruptResult (*interrupter)(ArkUI_GestureInterruptInfo* info))Sets a gesture interruption callback for a node.
ArkUI_GestureRecognizerType (*getGestureType)(ArkUI_GestureRecognizer* recognizer)Obtains the type of a gesture.
int32_t (*setInnerGestureParallelTo)(ArkUI_NodeHandle node, void* userData, ArkUI_GestureRecognizer* (*parallelInnerGesture)(ArkUI_ParallelInnerGestureEvent* event))Sets the callback function for the parallel internal gesture event.
ArkUI_GestureRecognizer* (*createTapGestureWithDistanceThreshold)(int32_t countNum, int32_t fingersNum, double distanceThreshold)Creates a tap gesture that is subject to distance restrictions.
1. This API is used to trigger a tap gesture with one, two, or more taps.
2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms.
3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, gesture recognition fails.
4. When multiple fingers are configured for a gesture, the recognition fails if the number of fingers touching the screen within 300 ms of the initial touch is less than the required count, or if the number of fingers lifted from the screen within 300 ms of the first finger's being lifted is less than the required count.
5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized.
6. If the finger moves beyond the preset distance limit, gesture recognition fails.

Member Function Description

createTapGesture()

ArkUI_GestureRecognizer* (*createTapGesture)(int32_t countNum, int32_t fingersNum)

Description

Creates a tap gesture.

  1. This API is used to trigger a tap gesture with one, two, or more taps.
  2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms.
  3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, gesture recognition fails.
  4. If the value is greater than 1, the tap gesture will fail to be recognized when the required number of fingers is not pressed within 300 milliseconds after the first finger touches down, or when the required number of fingers is not lifted within 300 milliseconds after the first finger is lifted.
  5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized.

Parameters

NameDescription
int32_t countNumNumber of consecutive taps. If the value is less than 1 or is not set, the default value 1 is used.
int32_t fingersNumNumber of fingers required to trigger the tap gesture. The value ranges from 1 to 10. If the value is less than 1 or is not set, the default value 1 is used.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture.

createLongPressGesture()

ArkUI_GestureRecognizer* (*createLongPressGesture)(int32_t fingersNum, bool repeatResult, int32_t durationNum)

Description

Creates a long press gesture.

  1. This API is used to trigger a long press gesture, which requires one or more fingers with a minimum 500 ms hold-down time.

  2. In components that support drag actions by default, such as Text, TextInput, TextArea, HyperLink, Image, and RichEditor,

    the long press gesture may conflict with the drag action. If this occurs, the event priority is determined as follows:

    If the minimum duration of the long press gesture is less than 500 ms, the long press gesture receives a higher response priority than the drag action.

    If the minimum duration of the long press gesture is greater than or equal to 500 ms, the drag action receives a higher response priority than the long press gesture.

  3. If a finger moves more than 15 px after being pressed, the gesture recognition fails.

Parameters

NameDescription
int32_t fingersNumMinimum number of fingers to trigger a long press gesture. The value ranges from 1 to 10. If the value is out of the range, the default value 1 is used.
bool repeatResultWhether to continuously trigger the event callback.
The value true means to continuously trigger event callbacks, and false means the opposite.
int32_t durationNumMinimum hold-down time, in ms. If the value is less than or equal to 0, the default value 500 is used.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture.

createPanGesture()

ArkUI_GestureRecognizer* (*createPanGesture)(int32_t fingersNum, ArkUI_GestureDirectionMask directions, double distanceNum)

Description

Creates a swipe gesture.

  1. This API is used to trigger a pan gesture when the movement distance of a finger on the screen exceeds the minimum value.
  2. If a pan gesture and a tab swipe occur at the same time, set distanceNum to 1 so that the gesture can be more easily recognized.

Parameters

NameDescription
int32_t fingersNumMinimum number of fingers to trigger a pan gesture. The value ranges from 1 to 10. If the value is less than 1 or is not set, the default value 1 is used.
ArkUI_GestureDirectionMask directionsPan direction. The value supports the AND (&) and OR (|) operations.
double distanceNumMinimum pan distance to trigger the gesture, in px. If this parameter is set to a value less than or equal to 0, the default value 5px is used.

Returns

TypeDescription
ArkUI_GestureRecognizer*Pointer to the created gesture.

createPinchGesture()

ArkUI_GestureRecognizer* (*createPinchGesture)(int32_t fingersNum, double distanceNum)

Description

Creates a pinch gesture.

  1. This API is used to trigger a pinch gesture, which requires two to five fingers with a minimum pinch distance of pixels specified by distanceNum.
  2. While more fingers than the minimum number can be pressed to trigger the gesture, only the first fingers of the minimum number participate in gesture calculation.

Parameters

NameDescription
int32_t fingersNumMinimum number of fingers required to trigger the pinch gesture. The value ranges from 2 to 5. If the value is out of the range, the default value 2 is used.
double distanceNumMinimum recognition distance, in px. If this parameter is set to a value less than or equal to 0, the default value 5px is used.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture.

createRotationGesture()

ArkUI_GestureRecognizer* (*createRotationGesture)(int32_t fingersNum, double angleNum)

Description

Creates a rotation gesture.

  1. This API is used to trigger a rotation gesture, which requires two to five fingers with a minimum 1-degree rotation angle.
  2. While more fingers than the minimum number can be pressed to trigger the gesture, only the first two fingers participate in gesture calculation.

Parameters

NameDescription
int32_t fingersNumMinimum number of fingers required to trigger the rotation gesture. The value ranges from 2 to 5. If the value is out of the range, the default value 2 is used.
double angleNumMinimum angle change required to trigger the rotation gesture, in degrees (deg). The default value is 1. If this parameter is set to a value less than or equal to 0 or greater than 360, the default value 1 is used.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture.

createSwipeGesture()

ArkUI_GestureRecognizer* (*createSwipeGesture)(int32_t fingersNum, ArkUI_GestureDirectionMask directions, double speedNum)

Description

Creates a swipe gesture. This API is used to implement a swipe gesture, which can be recognized when the swipe speed (px/s) is higher than that specified by speedNum.

Parameters

NameDescription
int32_t fingersNumMinimum number of fingers required to trigger the swipe gesture. The value ranges from 1 to 10.
ArkUI_GestureDirectionMask directionsDirections in which the swipe gesture can be recognized.
double speedNumMinimum speed required to recognize the swipe gesture, in px/s. If this parameter is set to a value less than or equal to 0, the default value 100px/s is used.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture.

createGroupGesture()

ArkUI_GestureRecognizer* (*createGroupGesture)(ArkUI_GroupGestureMode gestureMode)

Description

Creates a gesture group.

Parameters

NameDescription
ArkUI_GroupGestureMode gestureModeGesture group mode.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture group.

dispose()

void (*dispose)(ArkUI_GestureRecognizer* recognizer)

Description

Disposes of a gesture to release resources.

Parameters

NameDescription
ArkUI_GestureRecognizer* recognizerPointer to the gesture to be disposed of.

addChildGesture()

int32_t (*addChildGesture)(ArkUI_GestureRecognizer* group, ArkUI_GestureRecognizer* child)

Description

Adds a gesture to a gesture group.

Parameters

NameDescription
ArkUI_GestureRecognizer* groupPointer to the target gesture group.
ArkUI_GestureRecognizer* childPointer to the target gesture.

Returns

TypeDescription
int32_tError code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs, for example, attempting to add a gesture to an object that is not a gesture group.

removeChildGesture()

int32_t (*removeChildGesture)(ArkUI_GestureRecognizer* group, ArkUI_GestureRecognizer* child)

Description

Removes a gesture from a gesture group.

Parameters

NameDescription
ArkUI_GestureRecognizer* groupPointer to the target gesture group.
ArkUI_GestureRecognizer* childPointer to the target gesture.

Returns

TypeDescription
int32_tError code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

setGestureEventTarget()

int32_t (*setGestureEventTarget)(ArkUI_GestureRecognizer* recognizer, ArkUI_GestureEventActionTypeMask actionTypeMask, void* extraParams,void (*targetReceiver)(ArkUI_GestureEvent* event, void* extraParams))

Description

Registers a callback for gestures.

Parameters

NameDescription
ArkUI_GestureRecognizer* recognizerPointer to a gesture recognizer.
ArkUI_GestureEventActionTypeMask actionTypeMaskGesture event types. Multiple callbacks can be registered at once, with the callback event types distinguished in the callbacks. Example: actionTypeMask = GESTURE_EVENT_ACTION_ACCEPT |GESTURE_EVENT_ACTION_UPDATE;
void* extraParamsContext passed in the targetReceiver callback.
targetReceiverCallback to register for processing the gesture event types. event indicates the gesture callback data.

Returns

TypeDescription
int32_tError code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

addGestureToNode()

int32_t (*addGestureToNode)(ArkUI_NodeHandle node, ArkUI_GestureRecognizer* recognizer, ArkUI_GesturePriority mode, ArkUI_GestureMask mask)

Description

Adds a gesture to a UI component.

Parameters

NameDescription
ArkUI_NodeHandle nodePointer to the ArkUI component node to which you want to add the gesture.
ArkUI_GestureRecognizer* recognizerGesture to be added to the UI component.
ArkUI_GesturePriority modeMode of the gesture.
ArkUI_GestureMask maskGesture masking mode.

Returns

TypeDescription
int32_tError code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

removeGestureFromNode()

int32_t (*removeGestureFromNode)(ArkUI_NodeHandle node, ArkUI_GestureRecognizer* recognizer)

Description

Removes a gesture from a node.

Parameters

NameDescription
ArkUI_NodeHandle nodePointer to the node from which you want to remove the gesture.
ArkUI_GestureRecognizer* recognizerGesture to be removed.

Returns

TypeDescription
int32_tError code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

setGestureInterrupterToNode()

int32_t (*setGestureInterrupterToNode)(ArkUI_NodeHandle node, ArkUI_GestureInterruptResult (*interrupter)(ArkUI_GestureInterruptInfo* info))

Description

Sets a gesture interruption callback for a node.

Parameters

NameDescription
ArkUI_NodeHandle nodePointer to the ArkUI node for which you want to set a gesture interruption callback.
ArkUI_GestureInterruptResult (*interrupter)(ArkUI_GestureInterruptInfo* info)Gesture interruption callback to set. info returns the gesture interruption data. If interrupter returns GESTURE_INTERRUPT_RESULT_CONTINUE, the gesture recognition process continues. If it returns GESTURE_INTERRUPT_RESULT_REJECT, the gesture recognition process is paused. If this parameter is set to a null pointer, the callback function is unregistered.
Note: After the event interruption callback is registered, it will be available in subsequent single-gesture processing. That is, even if you use the setGestureInterrupterToNode API to reset the gesture interruption callback to undefined or use the dispose API to dispose of the gesture that is about to be triggered, the callback will still respond when the trigger condition is met. If the object used in the callback has been released before the callback is triggered, you need to protect the object.

Returns

TypeDescription
int32_tError code.
Returns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

getGestureType()

ArkUI_GestureRecognizerType (*getGestureType)(ArkUI_GestureRecognizer* recognizer)

Description

Obtains the type of a gesture.

Parameters

NameDescription
ArkUI_GestureRecognizer* recognizerPointer to the gesture.

Returns

TypeDescription
ArkUI_GestureRecognizerTypeReturns the gesture type.

setInnerGestureParallelTo()

int32_t (*setInnerGestureParallelTo)(ArkUI_NodeHandle node, void* userData, ArkUI_GestureRecognizer* (*parallelInnerGesture)(ArkUI_ParallelInnerGestureEvent* event))

Description

Sets the callback function for the parallel internal gesture event.

Parameters

NameDescription
ArkUI_NodeHandle nodePointer to the ArkUI node for which you want to set the callback of the parallel internal gesture event.
void* userDataCustom data.
parallelInnerGestureParallel internal gesture event. event returns the data of the parallel internal gesture event. parallelInnerGesture returns the pointer to the gesture recognizer that requires parallel recognition.

Returns

TypeDescription
int32_tReturns ARKUI_ERROR_CODE_NO_ERROR if the operation is successful.
Returns ARKUI_ERROR_CODE_PARAM_INVALID if a parameter error occurs.

createTapGestureWithDistanceThreshold()

ArkUI_GestureRecognizer* (*createTapGestureWithDistanceThreshold)(int32_t countNum, int32_t fingersNum, double distanceThreshold)

Description

Creates a tap gesture that is subject to distance restrictions.

  1. This API is used to trigger a tap gesture with one, two, or more taps.
  2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms.
  3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, gesture recognition fails.
  4. If the value is greater than 1, the tap gesture will fail to be recognized when the required number of fingers is not pressed within 300 milliseconds after the first finger touches down, or when the required number of fingers is not lifted within 300 milliseconds after the first finger is lifted.
  5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized.
  6. If the finger moves beyond the preset distance limit, gesture recognition fails.

Parameters

NameDescription
int32_t countNumNumber of consecutive taps. If the value is less than 1 or is not set, the default value 1 is used.
int32_t fingersNumNumber of fingers required to trigger the tap gesture. The value ranges from 1 to 10. If the value is less than 1 or is not set, the default value 1 is used.
double distanceThresholdAllowed moving distance of a finger. If the value is less than 0 or is not set, it will be converted to the default value of infinity.

Returns

TypeDescription
ArkUI_GestureRecognizer*Returns the pointer to the created gesture.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-apis-uicontext-contextmenucontroller

openharmony 鸿蒙 errorcode-canvas

openharmony 鸿蒙 capi-oh-nativexcomponent-native-xcomponent-oh-nativexcomponent

openharmony 鸿蒙 errorcode-bindSheet

openharmony 鸿蒙 js-apis-arkui-uiExtension-sys

openharmony 鸿蒙 capi-arkui-accessibility-arkui-accessibilityeventinfo

openharmony 鸿蒙 capi-arkui-rendernodeutils

openharmony 鸿蒙 js-apis-arkui-node

openharmony 鸿蒙 capi-native-node-h

openharmony 鸿蒙 capi-arkui-nativemodule-arkui-listitemswipeactionitem

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/VDRl10OF