1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup ArkUI_NativeModule 18 * @{ 19 * 20 * @brief Defines APIs for ArkUI to register gesture callbacks on the native side. 21 * 22 * @since 12 23 */ 24 25 /** 26 * @file native_gesture.h 27 * 28 * @brief Provides type definitions for <b>NativeGesture</b> APIs. 29 * 30 * @library libace_ndk.z.so 31 * @syscap SystemCapability.ArkUI.ArkUI.Full 32 * @since 12 33 */ 34 35 #ifndef ARKUI_NATIVE_GESTTURE_H 36 #define ARKUI_NATIVE_GESTTURE_H 37 38 #include "ui_input_event.h" 39 #include "native_type.h" 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** 46 * @brief Defines a gesture recognizer. 47 * 48 * @since 12 49 */ 50 typedef struct ArkUI_GestureRecognizer ArkUI_GestureRecognizer; 51 52 /** 53 * @brief Defines the gesture interruption information. 54 * 55 * @since 12 56 */ 57 typedef struct ArkUI_GestureInterruptInfo ArkUI_GestureInterruptInfo; 58 59 /** 60 * @brief Defines the gesture event. 61 * 62 * @since 12 63 */ 64 typedef struct ArkUI_GestureEvent ArkUI_GestureEvent; 65 66 /** 67 * @brief Enumerates gesture event types. 68 * 69 * @since 12 70 */ 71 typedef enum { 72 /** Triggered. */ 73 GESTURE_EVENT_ACTION_ACCEPT = 0x01, 74 75 /** Updated. */ 76 GESTURE_EVENT_ACTION_UPDATE = 0x02, 77 78 /** Ended. */ 79 GESTURE_EVENT_ACTION_END = 0x04, 80 81 /** Canceled. */ 82 GESTURE_EVENT_ACTION_CANCEL = 0x08, 83 } ArkUI_GestureEventActionType; 84 85 /** 86 * @brief Defines a set of gesture event types. 87 * 88 * Example: ArkUI_GestureEventActionTypeMask actions = GESTURE_EVENT_ACTION_ACCEPT | GESTURE_EVENT_ACTION_UPDATE;\n 89 * 90 * @since 12 91 */ 92 typedef uint32_t ArkUI_GestureEventActionTypeMask; 93 94 /** 95 * @brief Enumerates gesture event modes. 96 * 97 * @since 12 98 */ 99 typedef enum { 100 /** Normal. */ 101 NORMAL = 0, 102 103 /** High-priority. */ 104 PRIORITY = 1, 105 106 /** Parallel. */ 107 PARALLEL = 2, 108 } ArkUI_GesturePriority; 109 110 /** 111 * @brief Enumerates gesture group modes. 112 * 113 * @since 12 114 */ 115 typedef enum { 116 /* Sequential recognition. Gestures are recognized in the registration sequence until all gestures are recognized 117 * successfully. Once one gesture fails to be recognized, all subsequent gestures fail to be recognized. 118 * Only the last gesture in the gesture group can respond to the end event. */ 119 SEQUENTIAL_GROUP = 0, 120 121 /** Parallel recognition. Registered gestures are recognized concurrently until all gestures are recognized. 122 * The recognition result of each gesture does not affect each other. */ 123 PARALLEL_GROUP = 1, 124 125 /** Exclusive recognition. Registered gestures are identified concurrently. 126 * If one gesture is successfully recognized, gesture recognition ends. */ 127 EXCLUSIVE_GROUP = 2, 128 } ArkUI_GroupGestureMode; 129 130 /** 131 * @brief Enumerates gesture directions. 132 * 133 * @since 12 134 */ 135 typedef enum { 136 /** All directions. */ 137 GESTURE_DIRECTION_ALL = 0b1111, 138 139 /** Horizontal direction. */ 140 GESTURE_DIRECTION_HORIZONTAL = 0b0011, 141 142 /** Vertical direction. */ 143 GESTURE_DIRECTION_VERTICAL = 0b1100, 144 145 /** Leftward. */ 146 GESTURE_DIRECTION_LEFT = 0b0001, 147 148 /** Rightward. */ 149 GESTURE_DIRECTION_RIGHT = 0b0010, 150 151 /** Upward. */ 152 GESTURE_DIRECTION_UP = 0b0100, 153 154 /** Downward. */ 155 GESTURE_DIRECTION_DOWN = 0b1000, 156 157 /** None. */ 158 GESTURE_DIRECTION_NONE = 0, 159 } ArkUI_GestureDirection; 160 161 /** 162 * @brief Defines a set of gesture directions. 163 * 164 * Example: ArkUI_GestureDirectionMask directions = GESTURE_DIRECTION_LEFT | GESTURE_DIRECTION_RIGHT \n 165 * This example indicates that the leftward and rightward directions are supported. \n 166 * 167 * @since 12 168 */ 169 typedef uint32_t ArkUI_GestureDirectionMask; 170 171 /** 172 * @brief Enumerates gesture masking modes. 173 * 174 * @since 12 175 */ 176 typedef enum { 177 /** The gestures of child components are enabled and recognized based on the default gesture recognition sequence.*/ 178 NORMAL_GESTURE_MASK = 0, 179 180 /** The gestures of child components are disabled, including the built-in gestures. */ 181 IGNORE_INTERNAL_GESTURE_MASK, 182 } ArkUI_GestureMask; 183 184 /** 185 * @brief Enumerates gesture types. 186 * 187 * @since 12 188 */ 189 typedef enum { 190 /** Tap. */ 191 TAP_GESTURE = 0, 192 193 /** Long press. */ 194 LONG_PRESS_GESTURE, 195 196 /** Pan. */ 197 PAN_GESTURE, 198 199 /** Pinch. */ 200 PINCH_GESTURE, 201 202 /** Rotate. */ 203 ROTATION_GESTURE, 204 205 /** Swipe. */ 206 SWIPE_GESTURE, 207 208 /** A group of gestures. */ 209 GROUP_GESTURE, 210 } ArkUI_GestureRecognizerType; 211 212 /** 213 * @brief Enumerates gesture interruption results. 214 * 215 * @since 12 216 */ 217 typedef enum { 218 /** The gesture recognition process continues. */ 219 GESTURE_INTERRUPT_RESULT_CONTINUE = 0, 220 221 /** The gesture recognition process is paused. */ 222 GESTURE_INTERRUPT_RESULT_REJECT, 223 } ArkUI_GestureInterruptResult; 224 225 /** 226 * @brief Enumerates the gesture recognizer states. 227 * 228 * @since 12 229 */ 230 typedef enum { 231 /** Ready. */ 232 ARKUI_GESTURE_RECOGNIZER_STATE_READY = 0, 233 234 /** Detecting. */ 235 ARKUI_GESTURE_RECOGNIZER_STATE_DETECTING = 1, 236 237 /** Pending. */ 238 ARKUI_GESTURE_RECOGNIZER_STATE_PENDING = 2, 239 240 /** Blocked. */ 241 ARKUI_GESTURE_RECOGNIZER_STATE_BLOCKED = 3, 242 243 /** Successful. */ 244 ARKUI_GESTURE_RECOGNIZER_STATE_SUCCESSFUL = 4, 245 246 /** Failed. */ 247 ARKUI_GESTURE_RECOGNIZER_STATE_FAILED = 5, 248 } ArkUI_GestureRecognizerState; 249 250 /** 251 * @brief Defines the gesture recognizer handle. 252 * 253 * @since 12 254 */ 255 typedef ArkUI_GestureRecognizer* ArkUI_GestureRecognizerHandle; 256 257 /** 258 * @brief Defines the gesture recognizer handle array. 259 * 260 * @since 12 261 */ 262 typedef ArkUI_GestureRecognizerHandle* ArkUI_GestureRecognizerHandleArray; 263 264 /** 265 * @brief Defines a <b>GestureEventTargetInfo</b> object that provides information about a gesture event target. 266 * 267 * @since 12 268 */ 269 typedef struct ArkUI_GestureEventTargetInfo ArkUI_GestureEventTargetInfo; 270 271 /** 272 * @brief Defines a parallel internal gesture event. 273 * 274 * @since 12 275 */ 276 typedef struct ArkUI_ParallelInnerGestureEvent ArkUI_ParallelInnerGestureEvent; 277 278 /** 279 * @brief Defines a touch recognizer. 280 * 281 * @since 15 282 */ 283 typedef struct ArkUI_TouchRecognizer ArkUI_TouchRecognizer; 284 285 /** 286 * @brief Defines a touch recognizer handle. 287 * 288 * @since 15 289 */ 290 typedef ArkUI_TouchRecognizer* ArkUI_TouchRecognizerHandle; 291 292 /** 293 * @brief Defines an array of touch recognizer handle. 294 * 295 * @since 15 296 */ 297 typedef ArkUI_TouchRecognizerHandle* ArkUI_TouchRecognizerHandleArray; 298 299 /** 300 * @brief Defines a callback function for notifying gesture recognizer destruction. 301 * @since 12 302 */ 303 typedef void (*ArkUI_GestureRecognizerDisposeNotifyCallback)(ArkUI_GestureRecognizer* recognizer, void* userData); 304 305 /** 306 * @brief Checks whether a gesture is a built-in gesture of the component. 307 * 308 * @param event Indicates the pointer to the gesture interruption information. 309 * @return Returns <b>true</b> if the gesture is a built-in gesture; returns <b>false</b> otherwise. 310 311 * @since 12 312 */ 313 bool OH_ArkUI_GestureInterruptInfo_GetSystemFlag(const ArkUI_GestureInterruptInfo* event); 314 315 /** 316 * @brief Obtains the pointer to interrupted gesture recognizer. 317 * 318 * @param event Indicates the pointer to the gesture interruption information. 319 * @return Returns the pointer to interrupted gesture recognizer. 320 * @since 12 321 */ 322 ArkUI_GestureRecognizer* OH_ArkUI_GestureInterruptInfo_GetRecognizer(const ArkUI_GestureInterruptInfo* event); 323 324 /** 325 * @brief Obtains the pointer to the interrupted gesture event. 326 * 327 * @param event Indicates the pointer to the gesture interruption information. 328 * @return Returns the pointer to the interrupted gesture event. 329 * @since 12 330 */ 331 ArkUI_GestureEvent* OH_ArkUI_GestureInterruptInfo_GetGestureEvent(const ArkUI_GestureInterruptInfo* event); 332 333 /** 334 * @brief Obtains the type of the system gesture to trigger. 335 * 336 * @param event Indicates the pointer to the gesture interruption information. 337 * @return Returns the type of the system gesture to trigger. If the gesture to trigger is not a system gesture, 338 * <b>-1</b> is returned. 339 * @since 12 340 */ 341 int32_t OH_ArkUI_GestureInterruptInfo_GetSystemRecognizerType(const ArkUI_GestureInterruptInfo* event); 342 343 /** 344 * @brief Get the touch recognizer handles from the gesture interrupt info. 345 * 346 * @param info Indicates the pointer to a gesture interrupt info. 347 * @param recognizers Indicates the array of touch recognizer handles. 348 * @param size Indicates the size of recognizers. 349 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 350 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 351 * @since 15 352 */ 353 int32_t OH_ArkUI_GestureInterruptInfo_GetTouchRecognizers( 354 const ArkUI_GestureInterruptInfo* info, ArkUI_TouchRecognizerHandleArray* recognizers, int32_t* size); 355 356 /** 357 * @brief Get component object of the specific touch recognizer. 358 * 359 * @param recognizer Indicates the pointer to the TouchRecognizer. 360 * @return Get component object of the specific touch recognizer. 361 * @since 15 362 */ 363 ArkUI_NodeHandle OH_ArkUI_TouchRecognizer_GetNodeHandle(const ArkUI_TouchRecognizerHandle recognizer); 364 365 /** 366 * @brief Send touch-cancel event to the touch recognizer in a gesture interruption callback. 367 * 368 * @param recognizer Indicates the touch recognizer handle. 369 * @param info Indicates the pointer to a gesture interrupt info. 370 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 371 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 372 * @since 15 373 */ 374 int32_t OH_ArkUI_TouchRecognizer_CancelTouch(ArkUI_TouchRecognizerHandle recognizer, ArkUI_GestureInterruptInfo* info); 375 376 /** 377 * @brief Obtains the gesture event type. 378 * 379 * @param event Indicates the pointer to the gesture event. 380 * @return Returns the gesture event type. 381 * @since 12 382 */ 383 ArkUI_GestureEventActionType OH_ArkUI_GestureEvent_GetActionType(const ArkUI_GestureEvent* event); 384 385 /** 386 * @brief Obtains gesture input. 387 * 388 * @param event Indicates the pointer to the gesture event. 389 * @return Returns the pointer to the input event of the gesture event. 390 * @since 12 391 */ 392 const ArkUI_UIInputEvent* OH_ArkUI_GestureEvent_GetRawInputEvent(const ArkUI_GestureEvent* event); 393 394 /** 395 * @brief Obtains the number of times that a long press gesture is triggered periodically. 396 * 397 * @param event Indicates the pointer to the gesture event. 398 * @return Returns the number of times that the long press gesture is triggered periodically. 399 * @since 12 400 */ 401 int32_t OH_ArkUI_LongPress_GetRepeatCount(const ArkUI_GestureEvent* event); 402 403 /** 404 * @brief Obtains the velocity of a pan gesture along the main axis. 405 * 406 * @param event Indicates the pointer to the gesture event. 407 * @return Returns the velocity of the pan gesture along the main axis, in px/s. 408 * The value is the square root of the sum of the squares of the velocity on the x-axis and y-axis. 409 * @since 12 410 */ 411 float OH_ArkUI_PanGesture_GetVelocity(const ArkUI_GestureEvent* event); 412 413 /** 414 * @brief Obtains the velocity of a pan gesture along the x-axis. 415 * 416 * @param event Indicates the pointer to the gesture event. 417 * @return Returns the velocity of the pan gesture along the x-axis, in px/s. 418 * @since 12 419 */ 420 float OH_ArkUI_PanGesture_GetVelocityX(const ArkUI_GestureEvent* event); 421 422 /** 423 * @brief Obtains the velocity of a pan gesture along the y-axis. 424 * 425 * @param event Indicates the pointer to the gesture event. 426 * @return Returns the velocity of the pan gesture along the y-axis, in px/s. 427 * @since 12 428 */ 429 float OH_ArkUI_PanGesture_GetVelocityY(const ArkUI_GestureEvent* event); 430 431 /** 432 * @brief Obtains the relative offset of a pan gesture along the x-axis. 433 * 434 * @param event Indicates the pointer to the gesture event. 435 * @return Returns the relative offset of the gesture along the x-axis, in px. 436 * @since 12 437 */ 438 float OH_ArkUI_PanGesture_GetOffsetX(const ArkUI_GestureEvent* event); 439 440 /** 441 * @brief Obtains the relative offset of a pan gesture along the y-axis. 442 * 443 * @param event Indicates the pointer to the gesture event. 444 * @return Returns the relative offset of the gesture along the y-axis, in px. 445 * @since 12 446 */ 447 float OH_ArkUI_PanGesture_GetOffsetY(const ArkUI_GestureEvent* event); 448 449 /** 450 * @brief Obtains the angle information of the swipe gesture. 451 * 452 * After a swipe gesture is recognized, a line connecting the two fingers is identified as the initial line. 453 * As the fingers swipe, the line between the fingers rotates. \n 454 * Based on the coordinates of the initial line's and current line's end points, the arc tangent function is used to 455 * calculate the respective included angle of the points relative to the horizontal direction \n 456 * by using the following formula: Rotation angle = arctan2(cy2-cy1,cx2-cx1) - arctan2(y2-y1,x2-x1). \n 457 * The initial line is used as the coordinate system. Values from 0 to 180 degrees represent clockwise rotation, 458 * while values from –180 to 0 degrees represent counterclockwise rotation. \n 459 * 460 * @param event Indicates the pointer to the gesture event. 461 * @return Returns the angle of the swipe gesture, which is the result obtained based on the aforementioned formula. 462 * @since 12 463 */ 464 float OH_ArkUI_SwipeGesture_GetAngle(const ArkUI_GestureEvent* event); 465 466 /** 467 * @brief Obtains the average velocity of all fingers used in the swipe gesture. 468 * 469 * @param event Indicates the pointer to the gesture event. 470 * @return Returns the average velocity of all fingers used in the swipe gesture, in px/s. 471 * @since 12 472 */ 473 float OH_ArkUI_SwipeGesture_GetVelocity(const ArkUI_GestureEvent* event); 474 475 /** 476 * @brief Obtains the angle information of a rotation gesture. 477 * 478 * @param event Indicates the pointer to the gesture event. 479 * @return Returns the rotation angle. 480 * @since 12 481 */ 482 float OH_ArkUI_RotationGesture_GetAngle(const ArkUI_GestureEvent* event); 483 484 /** 485 * @brief Obtains the scale ratio of a pinch gesture. 486 * 487 * @param event Indicates the pointer to the gesture event. 488 * @return Returns the scale ratio. 489 * @since 12 490 */ 491 float OH_ArkUI_PinchGesture_GetScale(const ArkUI_GestureEvent* event); 492 493 /** 494 * @brief Obtains the X coordinate of the center of the pinch gesture, in vp, 495 * relative to the upper left corner of the current component. 496 * 497 * @param event Indicates the pointer to the gesture event. 498 * @return Returns the X coordinate of the center of the pinch gesture, in vp, 499 * relative to the upper left corner of the current component. 500 * @since 12 501 */ 502 float OH_ArkUI_PinchGesture_GetCenterX(const ArkUI_GestureEvent* event); 503 504 /** 505 * @brief Obtains the Y coordinate of the center of the pinch gesture, in vp, 506 * relative to the upper left corner of the current component. 507 * 508 * @param event Indicates the pointer to the gesture event. 509 * @return Returns the Y coordinate of the center of the pinch gesture, in vp, 510 * relative to the upper left corner of the current component. 511 * @since 12 512 */ 513 float OH_ArkUI_PinchGesture_GetCenterY(const ArkUI_GestureEvent* event); 514 515 /** 516 * @brief Obtains information about a gesture response chain. 517 * 518 * @param event Indicates the pointer to the gesture interruption information. 519 * @param responseChain Indicates the pointer to an array of gesture recognizers on the response chain. 520 * @param count Indicates the pointer to the number of gesture recognizers on the response chain. 521 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 522 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 523 * @since 12 524 */ 525 int32_t OH_ArkUI_GetResponseRecognizersFromInterruptInfo(const ArkUI_GestureInterruptInfo* event, 526 ArkUI_GestureRecognizerHandleArray* responseChain, int32_t* count); 527 528 /** 529 * @brief Sets the enabled state of a gesture recognizer. 530 * 531 * @param recognizer Indicates the pointer to a gesture recognizer. 532 * @param enabled Indicates the enabled state. 533 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 534 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 535 * @since 12 536 */ 537 int32_t OH_ArkUI_SetGestureRecognizerEnabled(ArkUI_GestureRecognizer* recognizer, bool enabled); 538 539 /** 540 * @brief Sets whether to enable strict finger count checking. If this feature is enabled and the actual number of touch 541 * fingers does not match the set number, the gesture recognition fails. 542 * 543 * @param recognizer Indicates the pointer to a gesture recognizer. 544 * @param limitFingerCount Indicates whether to enable strict finger count checking. 545 * @return Returns <b>0</b> if the operation is successful. 546 * Returns <b>401</b> if a parameter error occurs. 547 * @since 15 548 */ 549 int32_t OH_ArkUI_SetGestureRecognizerLimitFingerCount(ArkUI_GestureRecognizer* recognizer, bool limitFingerCount); 550 551 552 /** 553 * @brief Obtains the enabled state of a gesture recognizer. 554 * 555 * @param recognizer Indicates the pointer to a gesture recognizer. 556 * @return Returns <b>true</b> if the gesture recognizer is enabled. 557 * Returns <b>false</b> if the gesture recognizer is disabled. 558 * @since 12 559 */ 560 bool OH_ArkUI_GetGestureRecognizerEnabled(ArkUI_GestureRecognizer* recognizer); 561 562 /** 563 * @brief Obtains the state of a gesture recognizer. 564 * 565 * @param recognizer Indicates the pointer to a gesture recognizer. 566 * @param state Indicates the pointer to the state of the gesture recognizer. 567 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 568 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 569 * @since 12 570 */ 571 int32_t OH_ArkUI_GetGestureRecognizerState(ArkUI_GestureRecognizer* recognizer, ArkUI_GestureRecognizerState* state); 572 573 /** 574 * @brief Obtains the information about a gesture event target. 575 * 576 * @param recognizer Indicates the pointer to a gesture recognizer. 577 * @param info Indicates the information about a gesture event target. 578 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 579 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 580 * @since 12 581 */ 582 int32_t OH_ArkUI_GetGestureEventTargetInfo(ArkUI_GestureRecognizer* recognizer, ArkUI_GestureEventTargetInfo** info); 583 584 /** 585 * @brief Obtains whether this scroll container is scrolled to the top. 586 * 587 * @param info Indicates the information about a gesture event target. 588 * @param ret Indicates whether the scroll container is scrolled to the top. 589 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 590 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 591 * Returns {@link ARKUI_ERROR_CODE_NON_SCROLLABLE_CONTAINER} if the component is not a scroll container. 592 * @since 12 593 */ 594 int32_t OH_ArkUI_GestureEventTargetInfo_IsScrollBegin(ArkUI_GestureEventTargetInfo* info, bool* ret); 595 596 /** 597 * @brief Obtains whether this scroll container is scrolled to the bottom. 598 * 599 * @param info Indicates the information about a gesture event target. 600 * @param ret Indicates whether the scroll container is scrolled to the bottom. 601 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 602 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 603 * Returns {@link ARKUI_ERROR_CODE_NON_SCROLLABLE_CONTAINER} if the component is not a scroll container. 604 * @since 12 605 */ 606 int32_t OH_ArkUI_GestureEventTargetInfo_IsScrollEnd(ArkUI_GestureEventTargetInfo* info, bool* ret); 607 608 /** 609 * @brief Obtains the direction of a pan gesture. 610 * 611 * @param recognizer Indicates the pointer to a gesture recognizer. 612 * @param directionMask Indicates the pan direction. 613 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 614 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 615 * @since 12 616 */ 617 int32_t OH_ArkUI_GetPanGestureDirectionMask(ArkUI_GestureRecognizer* recognizer, 618 ArkUI_GestureDirectionMask* directionMask); 619 620 /** 621 * @brief Obtains whether a gesture is a built-in gesture. 622 * 623 * @param recognizer Indicates the pointer to a gesture recognizer. 624 * @return Returns <b>true</b> if the gesture is a built-in gesture; returns <b>false</b> otherwise. 625 * @since 12 626 */ 627 bool OH_ArkUI_IsBuiltInGesture(ArkUI_GestureRecognizer* recognizer); 628 629 /** 630 * @brief Obtains the tag of a gesture recognizer. 631 * 632 * @param recognizer Indicates the pointer to a gesture recognizer. 633 * @param buffer Indicates the buffer. 634 * @param bufferSize Indicates the buffer size. 635 * @param result Indicates the length of the string to be written to the buffer. 636 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 637 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 638 * Returns {@link ARKUI_ERROR_CODE_BUFFER_SIZE_NOT_ENOUGH} if the buffer is not large enough. 639 * @since 12 640 */ 641 int32_t OH_ArkUI_GetGestureTag(ArkUI_GestureRecognizer* recognizer, char* buffer, int32_t bufferSize, int32_t* result); 642 643 /** 644 * @brief Obtains the ID of the component linked to a gesture recognizer. 645 * 646 * @param recognizer Indicates the pointer to a gesture recognizer. 647 * @param nodeId Indicates the component ID. 648 * @param size Indicates the buffer size. 649 * @param result Indicates the length of the string to be written to the buffer. 650 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 651 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 652 * Returns {@link ARKUI_ERROR_CODE_BUFFER_SIZE_NOT_ENOUGH} if the buffer is not large enough. 653 * @since 12 654 */ 655 int32_t OH_ArkUI_GetGestureBindNodeId(ArkUI_GestureRecognizer* recognizer, char* nodeId, int32_t size, 656 int32_t* result); 657 658 /** 659 * @brief Obtains whether a gesture recognizer is valid. 660 * 661 * @param recognizer Indicates the pointer to a gesture recognizer. 662 * @return Returns <b>true</b> if the gesture recognizer is valid. 663 * Returns <b>false</b> if the gesture recognizer is invalid. 664 * @since 12 665 */ 666 bool OH_ArkUI_IsGestureRecognizerValid(ArkUI_GestureRecognizer* recognizer); 667 668 /** 669 * @brief Obtains custom data in the parallel internal gesture event. 670 * 671 * @param event Indicates the pointer to a parallel internal gesture event. 672 * @return Returns the pointer to custom data. 673 * @since 12 674 */ 675 void* OH_ArkUI_ParallelInnerGestureEvent_GetUserData(ArkUI_ParallelInnerGestureEvent* event); 676 677 /** 678 * @brief Obtains the current gesture recognizer in a parallel internal gesture event. 679 * 680 * @param event Indicates the pointer to a parallel internal gesture event. 681 * @return Returns the pointer to the current gesture recognizer. 682 * @since 12 683 */ 684 ArkUI_GestureRecognizer* OH_ArkUI_ParallelInnerGestureEvent_GetCurrentRecognizer( 685 ArkUI_ParallelInnerGestureEvent* event); 686 687 /** 688 * @brief Obtains the conflicting gesture recognizers in a parallel internal gesture event. 689 * 690 * @param event Indicates the pointer to a parallel internal gesture event. 691 * @param array Indicates the pointer to the array of conflicting gesture recognizers. 692 * @param size Indicates the size of the array of conflicting gesture recognizers. 693 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 694 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 695 * @since 12 696 */ 697 int32_t OH_ArkUI_ParallelInnerGestureEvent_GetConflictRecognizers(ArkUI_ParallelInnerGestureEvent* event, 698 ArkUI_GestureRecognizerHandleArray* array, int32_t* size); 699 700 /** 701 * @brief Sets a callback function for notifying gesture recognizer destruction. 702 * 703 * @param recognizer Indicates the pointer to a gesture recognizer. 704 * @param callback Indicates the callback function for notifying gesture recognizer destruction. 705 * @param userData Indicates the custom data. 706 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 707 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 708 */ 709 int32_t OH_ArkUI_SetArkUIGestureRecognizerDisposeNotify(ArkUI_GestureRecognizer* recognizer, 710 ArkUI_GestureRecognizerDisposeNotifyCallback callback, void* userData); 711 712 ArkUI_NodeHandle OH_ArkUI_GestureEvent_GetNode(const ArkUI_GestureEvent* event); 713 /** 714 * @brief Defines the gesture APIs. 715 * 716 * @since 12 717 */ 718 typedef struct { 719 /** The struct version is 1. */ 720 int32_t version; 721 722 /** 723 * @brief Creates a tap gesture. 724 * 725 * 1. This API is used to trigger a tap gesture with one, two, or more taps. \n 726 * 2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms. \n 727 * 3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, 728 * gesture recognition fails. \n 729 * 4. If the value is greater than 1, the tap gesture will fail to be recognized when the number of fingers 730 * touching the screen within 300 ms of the first finger touch is less than the required number, \n 731 * or when the number of fingers lifted from the screen within 300 ms of the first finger's being lifted 732 * is less than the required number. \n 733 * 5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized. \n 734 * 735 * @param countNum Indicates the number of consecutive taps. If the value is less than 1 or is not set, 736 * the default value <b>1</b> is used. 737 * @param fingersNum Indicates the number of fingers required to trigger a tap. The value ranges 738 * from 1 to 10. If the value is less than 1 or is not set, the default value <b>1</b> is used. 739 * @return Returns the pointer to the created gesture. 740 */ 741 ArkUI_GestureRecognizer* (*createTapGesture)(int32_t countNum, int32_t fingersNum); 742 743 /** 744 * @brief Creates a long press gesture. 745 * 746 * 1. This API is used to trigger a long press gesture, which requires one or more fingers with a minimum 747 * The value ranges 500 ms hold-down time. \n 748 * 2. In components that support drag actions by default, such as <b><Text></b>, <b><TextInput></b>, 749 * <b><TextArea></b>, <b><Hyperlink></b>, <b><Image></b>, and <b>RichEditor></b>, the long press gesture \n 750 * may conflict with the drag action. If this occurs, they are handled as follows: \n 751 * If the minimum duration of the long press gesture is less than 500 ms, the long press gesture receives 752 * a higher response priority than the drag action. \n 753 * If the minimum duration of the long press gesture is greater than or equal to 500 ms, 754 * the drag action receives a higher response priority than the long press gesture. \n 755 * 3. If a finger moves more than 15 px after being pressed, the gesture recognition fails. \n 756 * 757 * @param fingersNum Indicates the minimum number of fingers to trigger a long press gesture. 758 * The value ranges from 1 to 10. 759 * @param repeatResult Indicates whether to continuously trigger the event callback. 760 * @param durationNum Indicates the minimum hold-down time, in ms. 761 * If the value is less than or equal to 0, the default value <b>500</b> is used. 762 * @return Returns the pointer to the created gesture. 763 */ 764 ArkUI_GestureRecognizer* (*createLongPressGesture)(int32_t fingersNum, bool repeatResult, int32_t durationNum); 765 766 /** 767 * @brief Creates a pan gesture. 768 * 769 * 1. This API is used to trigger a pan gesture when the movement distance of a finger on the screen exceeds 770 * the minimum value. \n 771 * 2. If a pan gesture and a tab swipe occur at the same time, set <b>distanceNum</b> to <b>1</b> 772 * so that the gesture can be more easily recognized. \n 773 * 774 * @param fingersNum Indicates the minimum number of fingers to trigger a pan gesture. The value ranges from 1 to 10. 775 * If the value is less than 1 or is not set, the default value <b>1</b> is used. 776 * @param directions Indicates the pan direction. The value supports the AND (&) and OR (\|) operations. 777 * @param distanceNum Indicates the minimum pan distance to trigger the gesture, in vp. If this parameter is 778 * set to a value less than or equal to 0, the default value <b>5</b> is used. 779 * @return Returns the pointer to the created gesture. 780 */ 781 ArkUI_GestureRecognizer* (*createPanGesture)( 782 int32_t fingersNum, ArkUI_GestureDirectionMask directions, double distanceNum); 783 784 /** 785 * @brief Creates a pinch gesture. 786 * 787 * 1. This API is used to trigger a pinch gesture, which requires two to five fingers with a minimum 5 vp 788 * distance between the fingers. \n 789 * 2. While more fingers than the minimum number can be pressed to trigger the gesture, only the first 790 * fingers of the minimum number participate in gesture calculation. \n 791 * 792 * @param fingersNum Indicates the minimum number of fingers to trigger a pinch. The value ranges from 2 to 5. 793 * Default value: <b>2</b> 794 * @param distanceNum Indicates the minimum recognition distance, in px. If this parameter is set to a value less 795 * than or equal to 0, the default value <b>5</b> is used. 796 * @return Returns the pointer to the created gesture. 797 */ 798 ArkUI_GestureRecognizer* (*createPinchGesture)(int32_t fingersNum, double distanceNum); 799 800 /** 801 * @brief Creates a rotation gesture. 802 * 803 * 1. This API is used to trigger a rotation gesture, which requires two to five fingers with a 804 * minimum 1-degree rotation angle. \n 805 * 2. While more fingers than the minimum number can be pressed to trigger the gesture, only the first 806 * two fingers participate in gesture calculation. \n 807 * 808 * @param fingersNum Indicates the minimum number of fingers to trigger a rotation. The value ranges from 2 to 5. 809 * Default value: <b>2</b> 810 * @param angleNum Indicates the minimum degree that can trigger the rotation gesture. Default value: <b>1</b> 811 * If this parameter is set to a value less than or equal to 0 or greater than 360, 812 * the default value <b>1</b> is used. 813 * @return Returns the pointer to the created gesture. 814 */ 815 ArkUI_GestureRecognizer* (*createRotationGesture)(int32_t fingersNum, double angleNum); 816 817 /** 818 * @brief Creates a swipe gesture. 819 * 820 * This API is used to implement a swipe gesture, which can be recognized when the swipe speed is 100 821 * vp/s or higher. \n 822 * 823 * @param fingersNum Indicates the minimum number of fingers to trigger a swipe gesture. 824 * The value ranges from 1 to 10. 825 * @param directions Indicates the swipe direction. 826 * @param speedNum Indicates the minimum speed of the swipe gesture, in px/s. 827 * If this parameter is set to a value less than or equal to 0, the default value <b>100</b> is used. 828 * @return Returns the pointer to the created gesture. 829 */ 830 ArkUI_GestureRecognizer* (*createSwipeGesture)( 831 int32_t fingersNum, ArkUI_GestureDirectionMask directions, double speedNum); 832 833 /** 834 * @brief Creates a gesture group. 835 * 836 * @param gestureMode Indicates the gesture group mode. 837 * @return Returns the pointer to the created gesture group. 838 */ 839 ArkUI_GestureRecognizer* (*createGroupGesture)(ArkUI_GroupGestureMode gestureMode); 840 841 /** 842 * @brief Disposes a gesture to release resources. 843 * 844 * @param recognizer Indicates the pointer to the gesture to dispose. 845 */ 846 void (*dispose)(ArkUI_GestureRecognizer* recognizer); 847 848 /** 849 * @brief Adds a gesture to a gesture group. 850 * 851 * @param group Indicates the pointer to the gesture group. 852 * @param child Indicates the gesture to be added to the gesture group. 853 * @return Returns <b>0</b> if success. 854 * Returns <b>401</b> if a parameter exception occurs. Returns 401 if a parameter exception occurs. 855 */ 856 int32_t (*addChildGesture)(ArkUI_GestureRecognizer* group, ArkUI_GestureRecognizer* child); 857 858 /** 859 * @brief Removes a gesture to a gesture group. 860 * 861 * @param group Indicates the pointer to the gesture group. 862 * @param child Indicates the gesture to be removed to the gesture group. 863 * @return Returns <b>0</b> if success. 864 * Returns <b>401</b> if a parameter exception occurs. 865 */ 866 int32_t (*removeChildGesture)(ArkUI_GestureRecognizer* group, ArkUI_GestureRecognizer* child); 867 868 /** 869 * @brief Registers a callback for gestures. 870 * 871 * @param recognizer Indicates the pointer to the gesture recognizer. 872 * @param actionTypeMask Indicates the set of gesture event types. Multiple callbacks can be registered at once, 873 * with the callback event types distinguished in the callbacks. 874 * Example: actionTypeMask = GESTURE_EVENT_ACTION_ACCEPT | GESTURE_EVENT_ACTION_UPDATE; 875 * @param extraParams Indicates the context passed in the <b>targetReceiver</b> callback. 876 * @param targetReceiver Indicates the callback to register for processing the gesture event types. 877 * <b>event</b> indicates the gesture callback data. 878 * @return Returns <b>0</b> if success. 879 * Returns <b>401</b> if a parameter exception occurs. 880 */ 881 int32_t (*setGestureEventTarget)( 882 ArkUI_GestureRecognizer* recognizer, ArkUI_GestureEventActionTypeMask actionTypeMask, void* extraParams, 883 void (*targetReceiver)(ArkUI_GestureEvent* event, void* extraParams)); 884 885 /** 886 * @brief Adds a gesture to a UI component. 887 * 888 * @param node Indicates the UI component to which you want to add the gesture. 889 * @param recognizer Indicates the gesture to be added to the UI component. 890 * @param mode Indicates the gesture event mode. Available options are <b>NORMAL_GESTURE</b>, 891 * <b>PARALLEL_GESTURE</b>, and <b>PRIORITY_GESTURE</b>. 892 * @param mask Indicates the gesture masking mode. 893 * @return Returns <b>0</b> if success. 894 * Returns <b>401</b> if a parameter exception occurs. 895 */ 896 int32_t (*addGestureToNode)( 897 ArkUI_NodeHandle node, ArkUI_GestureRecognizer* recognizer, ArkUI_GesturePriority mode, ArkUI_GestureMask mask); 898 899 /** 900 * @brief Removes a gesture from a node. 901 * 902 * @param node Indicates the node from which you want to remove the gesture. 903 * @param recognizer Indicates the gesture to be removed. 904 * @return Returns <b>0</b> if success. 905 * Returns <b>401</b> if a parameter exception occurs. 906 */ 907 int32_t (*removeGestureFromNode)(ArkUI_NodeHandle node, ArkUI_GestureRecognizer* recognizer); 908 909 /** 910 * @brief Sets a gesture interruption callback for a node. 911 * 912 * @param node Indicates the node for which you want to set a gesture interruption callback. 913 * @param interrupter Indicates the gesture interruption callback to set. 914 * <b>info</b> indicates the gesture interruption data. If <b>interrupter</b> returns 915 * <b>GESTURE_INTERRUPT_RESULT_CONTINUE</b>, the gesture recognition process continues. If it returns 916 * <b>GESTURE_INTERRUPT_RESULT_REJECT</b>, the gesture recognition process is paused. 917 * @return Returns <b>0</b> if success. 918 * Returns <b>401</b> if a parameter exception occurs. 919 */ 920 int32_t (*setGestureInterrupterToNode)( 921 ArkUI_NodeHandle node, ArkUI_GestureInterruptResult (*interrupter)(ArkUI_GestureInterruptInfo* info)); 922 923 /** 924 * @brief Obtains the type of a gesture. 925 * 926 * @param recognizer Indicates the pointer to the gesture. 927 * @return Returns the gesture type. 928 */ 929 ArkUI_GestureRecognizerType (*getGestureType)(ArkUI_GestureRecognizer* recognizer); 930 931 /** 932 * @brief Sets the callback function for a parallel internal gesture event. 933 * 934 * @param node Indicates the ArkUI node for which the callback of a parallel internal gesture event is to be set. 935 * @param userData Indicates the custom data. 936 * @param parallelInnerGesture Indicates the parallel internal gesture event. <b>event</b> returns the data of the 937 * parallel internal gesture event; <b>parallelInnerGesture</b> returns the pointer to the gesture recognizer 938 * that requires parallel recognition. 939 * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if success. 940 * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. 941 */ 942 int32_t (*setInnerGestureParallelTo)( 943 ArkUI_NodeHandle node, void* userData, ArkUI_GestureRecognizer* (*parallelInnerGesture)( 944 ArkUI_ParallelInnerGestureEvent* event)); 945 946 /** 947 * @brief Creates a tap gesture that is subject to distance restrictions. 948 * 949 * 1. This API is used to trigger a tap gesture with one, two, or more taps. \n 950 * 2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms. \n 951 * 3. If the distance between the last tapped position and the current tapped position exceeds 60 vp, 952 * gesture recognition fails. \n 953 * 4. If the value is greater than 1, the tap gesture will fail to be recognized when the number of fingers 954 * touching the screen within 300 ms of the first finger touch is less than the required number, 955 * or when the number of fingers lifted from the screen within 300 ms of the first finger's being lifted 956 * is less than the required number. \n 957 * 5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized. \n 958 * 6. If the finger moves beyond the preset distance limit, gesture recognition fails. \n 959 * 960 * @param countNum Indicates the number of consecutive taps. If the value is less than 1 or is not set, the default 961 * value <b>1</b> is used. 962 * @param fingersNum Indicates the number of fingers required to trigger a tap. The value ranges from 1 to 10. 963 * If the value is less than 1 or is not set, the default value <b>1</b> is used. 964 * @param distanceThreshold Indicates the allowed moving distance of a finger. 965 * The unit of this parameter is px. 966 * If the value is less than 0, it will be converted to the default value of infinity. 967 * @return Returns the pointer to the created gesture. 968 */ 969 ArkUI_GestureRecognizer* (*createTapGestureWithDistanceThreshold)( 970 int32_t countNum, int32_t fingersNum, double distanceThreshold); 971 } ArkUI_NativeGestureAPI_1; 972 973 #ifdef __cplusplus 974 }; 975 #endif 976 977 #endif // ARKUI_NATIVE_GESTTURE_H 978 /** @} */