diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts index 056c0739c9ea7ff69896f6fad82cb7f50c8f8b8b..ede2730ff657f8b00872df69e6792e77a17d1b25 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts @@ -5407,8 +5407,8 @@ class UIGestureEvent { let panGesture: PanGestureHandler = gesture as PanGestureHandler; getUINativeModule().common.addPanGesture(this._nodePtr, priority, mask, panGesture.gestureTag, panGesture.allowedTypes, panGesture.fingers, panGesture.direction, panGesture.distance, - panGesture.limitFingerCount, panGesture.onActionStartCallback, panGesture.onActionUpdateCallback, - panGesture.onActionEndCallback, panGesture.onActionCancelCallback); + panGesture.limitFingerCount, panGesture.distanceMap, panGesture.onActionStartCallback, + panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback); break; } case CommonGestureType.SWIPE_GESTURE: { @@ -5508,8 +5508,9 @@ function addGestureToGroup(nodePtr: Object | null, gesture: any, gestureGroupPtr case CommonGestureType.PAN_GESTURE: { let panGesture: PanGestureHandler = gesture as PanGestureHandler; getUINativeModule().common.addPanGestureToGroup(nodePtr, panGesture.gestureTag, panGesture.allowedTypes, - panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.limitFingerCount, panGesture.onActionStartCallback, - panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr); + panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.limitFingerCount, + panGesture.distanceMap, panGesture.onActionStartCallback, panGesture.onActionUpdateCallback, + panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr); break; } case CommonGestureType.SWIPE_GESTURE: { diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkGesture.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkGesture.ts index 9ccebb3e15f6ab8448a3403ab1e81c9841dbb87b..3d55ca3623d1acb702ff066bb49308d049b21b65 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkGesture.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkGesture.ts @@ -113,6 +113,7 @@ class PanGestureHandler extends GestureHandler { direction?: PanDirection; distance?: number; limitFingerCount?: boolean; + distanceMap?: Map; gestureTag?: string; allowedTypes?: Array; onActionStartCallback?: Callback; @@ -126,6 +127,12 @@ class PanGestureHandler extends GestureHandler { this.direction = options.direction; this.distance = options.distance; this.limitFingerCount = options.isFingerCountLimited; + if (options.distanceMap !== undefined && options.distanceMap !== null) { + this.distanceMap = new Map(); + options.distanceMap.forEach((value, key) => { + this.distanceMap.set(key, value); + }); + } } } diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index 72be0fb6966a63ef7a6861865b6e054156ddf9f2..987f79c5cd9590350342cbe79221a3f315e7c930 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -4895,6 +4895,12 @@ class PanGestureHandler extends GestureHandler { this.direction = options.direction; this.distance = options.distance; this.limitFingerCount = options.isFingerCountLimited; + if (options.distanceMap !== undefined && options.distanceMap !== null) { + this.distanceMap = new Map(); + options.distanceMap.forEach((value, key) => { + this.distanceMap.set(key, value); + }); + } } } @@ -5301,7 +5307,7 @@ class UIGestureEvent { let panGesture = gesture; getUINativeModule().common.addPanGesture(this._nodePtr, priority, mask, panGesture.gestureTag, panGesture.allowedTypes, panGesture.fingers, panGesture.direction, panGesture.distance, - panGesture.limitFingerCount, panGesture.onActionStartCallback, + panGesture.limitFingerCount, panGesture.distanceMap, panGesture.onActionStartCallback, panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback); break; } @@ -5403,7 +5409,7 @@ function addGestureToGroup(nodePtr, gesture, gestureGroupPtr) { let panGesture = gesture; getUINativeModule().common.addPanGestureToGroup(nodePtr, panGesture.gestureTag, panGesture.allowedTypes, panGesture.fingers, panGesture.direction, panGesture.distance, - panGesture.limitFingerCount, panGesture.onActionStartCallback, + panGesture.limitFingerCount, panGesture.distanceMap, panGesture.onActionStartCallback, panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr); break; } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.cpp index 09854da46fa8cd1409cedff380d6e0c856cfc980..ccb8db49e04c6378af374afd278c3a43009484a2 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.cpp @@ -82,7 +82,6 @@ void JSGestureRecognizer::GetType(const JSCallbackInfo& args) args.SetReturnValue(JSRef::Make(ToJSValue(static_cast(type)))); } - void JSGestureRecognizer::GetFingers(const JSCallbackInfo& args) { args.SetReturnValue(JSRef::Make(ToJSValue(fingers_))); @@ -180,6 +179,39 @@ void JSGestureRecognizer::IsValid(const JSCallbackInfo& args) args.SetReturnValue(JSRef::Make(ToJSValue(isValid))); } +void JSPanRecognizer::GetDirection(const JSCallbackInfo& args) +{ + args.SetReturnValue(JSRef::Make(ToJSValue(direction_.type))); +} + +void JSPanRecognizer::GetPanDistance(const JSCallbackInfo& args) +{ + args.SetReturnValue(JSRef::Make(ToJSValue(distance_))); +} + +void JSPanRecognizer::GetPanDistanceMap(const JSCallbackInfo& args) +{ + auto vm = args.GetVm(); + CHECK_NULL_VOID(vm); + auto distanceMap = panda::MapRef::New(vm); + auto recognizer = JSGestureRecognizer::GetRecognizer().Upgrade(); + if (!recognizer) { + args.SetReturnValue(JsiRef(JsiObject(distanceMap))); + return; + } + auto panRecognizer = AceType::DynamicCast(recognizer); + if (!panRecognizer) { + args.SetReturnValue(JsiRef(JsiObject(distanceMap))); + return; + } + auto panDistanceMap = panRecognizer->GetDistanceMap(); + for (const auto& item : panDistanceMap) { + distanceMap->Set(vm, panda::NumberRef::New(vm, static_cast(item.first)), + panda::NumberRef::New(vm, item.second)); + } + args.SetReturnValue(JsiRef(JsiObject(distanceMap))); +} + void JSPinchRecognizer::GetDistance(const JSCallbackInfo& args) { auto recognizer = JSGestureRecognizer::GetRecognizer().Upgrade(); @@ -295,6 +327,9 @@ void JSPanRecognizer::JSBind(BindingTarget globalObj) JSClass::CustomMethod("getState", &JSGestureRecognizer::GetRefereeState); JSClass::CustomMethod("getPanGestureOptions", &JSPanRecognizer::GetPanGestureOptions); JSClass::CustomMethod("isValid", &JSGestureRecognizer::IsValid); + JSClass::CustomMethod("getDirection", &JSPanRecognizer::GetDirection); + JSClass::CustomMethod("getDistance", &JSPanRecognizer::GetPanDistance); + JSClass::CustomMethod("getDistanceMap", &JSPanRecognizer::GetPanDistanceMap); JSClass::Inherit(); JSClass::Bind(globalObj, &JSPanRecognizer::Constructor, &JSPanRecognizer::Destructor); } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.h b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.h index 0f7cd3ad7451200690ea12a560d7bee0b61d33d1..6238a37fb42521c924af7e08309bdb400b13d22f 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_recognizer.h @@ -199,6 +199,8 @@ public: JSMultiFingerRecognizer::Update(recognizer); SetPanGestureOptions( recognizer->GetFingers(), recognizer->GetDistance(), recognizer->GetDirection()); + direction_ = recognizer->GetDirection(); + distance_ = recognizer->GetDistance(); } void GetPanGestureOptions(const JSCallbackInfo& args) @@ -209,6 +211,11 @@ public: args.SetReturnValue(panGestureOptionObj); } + void GetDirection(const JSCallbackInfo& args); + + void GetPanDistance(const JSCallbackInfo& args); + + void GetPanDistanceMap(const JSCallbackInfo& args); private: static void Constructor(const JSCallbackInfo& args) { @@ -232,6 +239,8 @@ private: panGestureOption_->SetDirection(direction); } RefPtr panGestureOption_; + PanDirection direction_; + double distance_; }; class JSPinchRecognizer : public JSMultiFingerRecognizer { diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index d4010fa5dedda6d509b3a02a3163d202f05645b2..3b25e85c4021a27bf4aa7a6abb37e9abbb879f61 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -27,6 +27,7 @@ #include "bridge/declarative_frontend/engine/jsi/jsi_types.h" #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.h" #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_utils_bridge.h" +#include "bridge/declarative_frontend/jsview/js_gesture.h" #include "bridge/declarative_frontend/jsview/js_view_abstract.h" #include "bridge/declarative_frontend/jsview/js_view_context.h" #include "bridge/js_frontend/engine/jsi/ark_js_runtime.h" @@ -6979,6 +6980,26 @@ void CommonBridge::SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t } } +void CommonBridge::SetGestureDistanceMap(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, + ArkUIGesture* gesture) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_VOID(vm); + Local gestureDistanceMap = runtimeCallInfo->GetCallArgRef(argNumber); + if (!gestureDistanceMap.IsNull() && !gestureDistanceMap->IsUndefined() && gestureDistanceMap->IsMap(vm)) { + Local distanceMapRef(gestureDistanceMap); + int32_t distanceMapSize = distanceMapRef->GetSize(vm); + PanDistanceMap distanceMap = { { SourceTool::UNKNOWN, DEFAULT_PAN_DISTANCE.ConvertToPx() } }; + for (int32_t i = 0; i < distanceMapSize; i++) { + SourceTool sourceTool = static_cast(distanceMapRef->GetKey(vm, i)->ToNumber(vm)->Value()); + double distance = static_cast(distanceMapRef->GetValue(vm, i)->ToNumber(vm)->Value()); + distanceMap[sourceTool] = distance; + } + auto gesturePtr = Referenced::Claim(reinterpret_cast(gesture)); + gesturePtr->SetDistanceMap(distanceMap); + } +} + void CommonBridge::SetGestureAllowedTypes(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture) { @@ -8383,12 +8404,13 @@ ArkUINativeModuleValue CommonBridge::AddPanGesture(ArkUIRuntimeCallInfo* runtime GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, limitFingerCount, NUM_5); auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture( fingers, direction, distance, limitFingerCount, nullptr); + SetGestureDistanceMap(runtimeCallInfo, NUM_9, gesture); SetGestureTag(runtimeCallInfo, NUM_3, gesture); SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_9, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_10, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_11, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_12, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_10, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_11, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_12, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_13, gesture); GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease( nativeNode, gesture, priority, mask); return panda::JSValueRef::Undefined(vm); @@ -8540,13 +8562,14 @@ ArkUINativeModuleValue CommonBridge::AddPanGestureToGroup(ArkUIRuntimeCallInfo* GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, limitFingerCount, NUM_3); auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture( fingers, direction, distance, limitFingerCount, nullptr); + SetGestureDistanceMap(runtimeCallInfo, NUM_7, gesture); SetGestureTag(runtimeCallInfo, NUM_1, gesture); SetGestureAllowedTypes(runtimeCallInfo, NUM_2, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture); - SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture); - auto* group = GetGestureGroup(runtimeCallInfo, NUM_11); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_8, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_9, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_10, gesture); + SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_11, gesture); + auto* group = GetGestureGroup(runtimeCallInfo, NUM_12); GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture); return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h index 3c7026f72435147619b66a9d28ea96d5bbc056a3..1eaaa7701bcb206f93243825a881207c7dedb01f 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h @@ -291,6 +291,7 @@ public: static Local CreateHoverInfo(EcmaVM* vm, const HoverInfo& hoverInfo); static void GetGestureCommonValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& priority, int32_t& mask); static void SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture); + static void SetGestureDistanceMap(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture); static void SetGestureAllowedTypes( ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture); static void GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, diff --git a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp index db0e2419134f6a2b76f450bc8f99c5034108c932..8eb2350858f6adf83248566c724dc9dd30f9735b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp @@ -16,6 +16,7 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_gesture.h" #include "base/log/log_wrapper.h" +#include "bridge/common/utils/engine_helper.h" #include "bridge/declarative_frontend/jsview/models/gesture_model_impl.h" #include "core/components_ng/base/view_stack_model.h" #include "core/components_ng/pattern/gesture/gesture_model_ng.h" @@ -243,6 +244,7 @@ constexpr char PAN_DIRECTION[] = "direction"; constexpr char SWIPE_DIRECTION[] = "direction"; constexpr char ROTATION_ANGLE[] = "angle"; constexpr char LIMIT_FINGER_COUNT[] = "isFingerCountLimited"; +constexpr char GESTURE_DISTANCE_MAP[] = "distanceMap"; } // namespace void JSGesture::Create(const JSCallbackInfo& info) @@ -347,6 +349,56 @@ void JSLongPressGesture::Create(const JSCallbackInfo& args) LongPressGestureModel::GetInstance()->Create(fingersNum, repeatResult, durationNum, isLimitFingerCount); } +napi_value GetIteratorNext(const napi_env env, napi_value iterator, napi_value func, bool *done) +{ + napi_value next = nullptr; + NAPI_CALL(env, napi_call_function(env, iterator, func, 0, nullptr, &next)); + napi_value doneValue = nullptr; + NAPI_CALL(env, napi_get_named_property(env, next, "done", &doneValue)); + NAPI_CALL(env, napi_get_value_bool(env, doneValue, done)); + return next; +} + +napi_value JSPanGesture::ParsePanDistanceMap(JSRef jsDistanceMap, PanDistanceMap& distanceMap) +{ + napi_value emptyValue = nullptr; + auto engine = EngineHelper::GetCurrentEngine(); + CHECK_NULL_RETURN(engine, emptyValue); + NativeEngine* nativeEngine = engine->GetNativeEngine(); + CHECK_NULL_RETURN(nativeEngine, emptyValue); + auto env = reinterpret_cast(nativeEngine); + + auto jsVal = JSRef::Cast(jsDistanceMap); + panda::Local value = jsVal.Get().GetLocalHandle(); + JSValueWrapper valueWrapper = value; + napi_value nativeValue = nativeEngine->ValueToNapiValue(valueWrapper); + + // parse map object + napi_value entriesFunc = nullptr; + napi_value iterator = nullptr; + napi_value nextFunc = nullptr; + NAPI_CALL(env, napi_get_named_property(env, nativeValue, "entries", &entriesFunc)); + NAPI_CALL(env, napi_call_function(env, nativeValue, entriesFunc, 0, nullptr, &iterator)); + NAPI_CALL(env, napi_get_named_property(env, iterator, "next", &nextFunc)); + + bool done = false; + napi_value next = nullptr; + while ((next = GetIteratorNext(env, iterator, nextFunc, &done)) != nullptr && !done) { + napi_value entry = nullptr; + napi_value key = nullptr; + napi_value value = nullptr; + NAPI_CALL(env, napi_get_named_property(env, next, "value", &entry)); + NAPI_CALL(env, napi_get_element(env, entry, 0, &key)); + NAPI_CALL(env, napi_get_element(env, entry, 1, &value)); + int32_t sourceTool = 0; + NAPI_CALL(env, napi_get_value_int32(env, key, &sourceTool)); + double distance = 0.0; + NAPI_CALL(env, napi_get_value_double(env, value, &distance)); + distanceMap[static_cast(sourceTool)] = distance; + } + return next; +} + void JSPanGesture::Create(const JSCallbackInfo& args) { int32_t fingersNum = DEFAULT_PAN_FINGER; @@ -372,6 +424,7 @@ void JSPanGesture::Create(const JSCallbackInfo& args) JSRef distance = obj->GetProperty(GESTURE_DISTANCE); JSRef directionNum = obj->GetProperty(PAN_DIRECTION); JSRef limitFingerCount = obj->GetProperty(LIMIT_FINGER_COUNT); + JSRef jsDistanceMap = obj->GetProperty(GESTURE_DISTANCE_MAP); if (fingers->IsNumber()) { int32_t fingersNumber = fingers->ToNumber(); @@ -394,6 +447,9 @@ void JSPanGesture::Create(const JSCallbackInfo& args) if (limitFingerCount->IsBoolean()) { isLimitFingerCount = limitFingerCount->ToBoolean(); } + if (jsDistanceMap->IsObject()) { + ParsePanDistanceMap(jsDistanceMap, distanceMap); + } PanGestureModel::GetInstance()->Create(fingersNum, panDirection, distanceMap, isLimitFingerCount); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_gesture.h b/frameworks/bridge/declarative_frontend/jsview/js_gesture.h index ed7411075d22907a75fa9a0ae223d91d49f1810d..67de7185dd723d7c76ef3f4122f11fc49e639997 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_gesture.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_gesture.h @@ -104,6 +104,7 @@ public: ~JSPanGesture() override = default; static void Create(const JSCallbackInfo& args); + static napi_value ParsePanDistanceMap(JSRef jsDistanceMap, PanDistanceMap& distanceMap); }; class JSSwipeGesture : public JSGesture { @@ -161,4 +162,3 @@ public: }; } // namespace OHOS::Ace::Framework #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H - diff --git a/frameworks/core/components_ng/gestures/pan_gesture.cpp b/frameworks/core/components_ng/gestures/pan_gesture.cpp index f2c24cbf57b0b7364b7eac259039abd8c88f9757..36a20f3857879efbdcb602e3545be6fdfcab5d9f 100644 --- a/frameworks/core/components_ng/gestures/pan_gesture.cpp +++ b/frameworks/core/components_ng/gestures/pan_gesture.cpp @@ -147,5 +147,8 @@ int32_t PanGesture::Deserialize(const char* buff) return SizeofMe(); } - +void PanGesture::SetDistanceMap(const PanDistanceMap& distanceMap) +{ + distanceMap_ = distanceMap; +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/pan_gesture.h b/frameworks/core/components_ng/gestures/pan_gesture.h index ec39b609611970d71da8a78486ea88e181a8178c..dd9010411121d9c46d38878365e46b88b2af6e84 100644 --- a/frameworks/core/components_ng/gestures/pan_gesture.h +++ b/frameworks/core/components_ng/gestures/pan_gesture.h @@ -67,6 +67,13 @@ public: virtual int32_t Deserialize(const char* buff) override; + void SetDistanceMap(const PanDistanceMap& distanceMap); + + PanDistanceMap GetDistanceMap() const + { + return distanceMap_; + } + protected: RefPtr CreateRecognizer() override; diff --git a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h index 7e58458114d9d27380c48734659aad442cb30f5d..325c708e95c262dbb4ded376e21627d4724e35b3 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h @@ -80,6 +80,16 @@ public: return direction_; } + void SetDistanceMap(const PanDistanceMap& distanceMap) + { + distanceMap_ = distanceMap; + } + + PanDistanceMap GetDistanceMap() const + { + return distanceMap_; + } + void HandlePanGestureAccept( const GestureEvent& info, PanGestureState panGestureState, const std::unique_ptr& callback); diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 0e49836066fb92be2ed6d1fcfef4ca71ddb4eb97..bb2d9ec9d5aa4a0a43b9e3504bf2fac3353405eb 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -3660,6 +3660,8 @@ struct ArkUIGestureModifier { ArkUI_Int32 (*getLongPressGestureDuration)(ArkUIGestureRecognizer* recognizer, int* duration); ArkUI_Int32 (*getRotationGestureAngle)(ArkUIGestureRecognizer* recognizer, double* angle); ArkUI_Int32 (*getTapGestureDistanceThreshold)(ArkUIGestureRecognizer* recognizer, double* distanceThreshold); + ArkUI_Int32 (*setDistanceMap)(ArkUIGesture* gesture, int size, int* toolTypeArray, double* distanceArray); + ArkUI_Int32 (*getDistanceByToolType)(ArkUIGestureRecognizer* recognizer, int toolType, double* distance); ArkUI_Bool (*isBuiltInGesture)(ArkUIGestureRecognizer* recognizer); ArkUI_Int32 (*getGestureTag)( ArkUIGestureRecognizer* recognizer, char* buffer, ArkUI_Int32 bufferSize, ArkUI_Int32* result); diff --git a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp index 26c9462e4e58f40b686dd63822c062f77b2264c0..bc4d8d40962d5c2f10091a1d530b5e59db356c18 100644 --- a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp @@ -1035,6 +1035,34 @@ ArkUI_Int32 getTapGestureDistanceThreshold(ArkUIGestureRecognizer* recognizer, d return ARKUI_ERROR_CODE_NO_ERROR; } +ArkUI_Int32 setDistanceMap(ArkUIGesture* gesture, int size, int* toolTypeArray, double* distanceArray) +{ + PanDistanceMap distanceMap = { { SourceTool::UNKNOWN, DEFAULT_PAN_DISTANCE.ConvertToPx() } }; + for (int i = 0; i < size; i++) { + distanceMap[static_cast(toolTypeArray[i])] = distanceArray[i]; + } + auto gestureForDistanceMap = Referenced::Claim(reinterpret_cast(gesture)); + CHECK_NULL_RETURN(gestureForDistanceMap, ERROR_CODE_PARAM_INVALID); + gestureForDistanceMap->SetDistanceMap(distanceMap); + return ERROR_CODE_NO_ERROR; +} + +ArkUI_Int32 getDistanceByToolType(ArkUIGestureRecognizer* recognizer, int toolType, double* distance) +{ + auto* rawRecognizer = reinterpret_cast(recognizer->recognizer); + CHECK_NULL_RETURN(rawRecognizer, ERROR_CODE_PARAM_INVALID); + auto gestureRecognizer = AceType::Claim(rawRecognizer); + auto panRecognizer = AceType::DynamicCast(gestureRecognizer); + CHECK_NULL_RETURN(panRecognizer, ERROR_CODE_PARAM_INVALID); + PanDistanceMap distanceMap = panRecognizer->GetDistanceMap(); + auto iter = distanceMap.find(static_cast(toolType)); + if (iter == distanceMap.end()) { + return ERROR_CODE_PARAM_INVALID; + } + *distance = static_cast(iter->second); + return ERROR_CODE_NO_ERROR; +} + ArkUI_Bool isBuiltInGesture(ArkUIGestureRecognizer* recognizer) { auto* rawRecognizer = reinterpret_cast(recognizer->recognizer); @@ -1149,6 +1177,8 @@ const ArkUIGestureModifier* GetGestureModifier() .getLongPressGestureDuration = getLongPressGestureDuration, .getRotationGestureAngle = getRotationGestureAngle, .getTapGestureDistanceThreshold = getTapGestureDistanceThreshold, + .setDistanceMap = setDistanceMap, + .getDistanceByToolType = getDistanceByToolType, .isBuiltInGesture = isBuiltInGesture, .getGestureTag = getGestureTag, .getGestureBindNodeId = getGestureBindNodeId, diff --git a/interfaces/native/libace.ndk.json b/interfaces/native/libace.ndk.json index ad18f7a167cfcabdbe15b3106f49b9e4e238cc7e..60b71a01012f8c4ed2aec3125139ad14d1190252 100644 --- a/interfaces/native/libace.ndk.json +++ b/interfaces/native/libace.ndk.json @@ -3314,5 +3314,13 @@ { "first_introduced": "18", "name": "OH_ArkUI_TextCascadePickerRangeContentArray_Destroy" + }, + { + "first_introduced": "18", + "name": "OH_ArkUI_PanGesture_SetDistanceMap" + }, + { + "first_introduced": "18", + "name": "OH_ArkUI_PanGesture_GetDistanceByToolType" } ] \ No newline at end of file diff --git a/interfaces/native/native_gesture.h b/interfaces/native/native_gesture.h index d122ae437c26b2497cc7adba1848d524ea3bcadb..618a3f06a860f500ed60dd7f719b291470e48f9b 100644 --- a/interfaces/native/native_gesture.h +++ b/interfaces/native/native_gesture.h @@ -824,6 +824,39 @@ int32_t OH_ArkUI_GetGestureParam_angle(ArkUI_GestureRecognizer* recognizer, doub */ int32_t OH_ArkUI_GetGestureParam_distanceThreshold(ArkUI_GestureRecognizer* recognizer, double* distanceThreshold); +/** +* @brief Sets the minimum movement distance thresholds for gestures to be recognized by a gesture recognizer. +* +* @param recognizer Indicates the pointer to a gesture recognizer. +* @param size Size of the array of minimum movement distance thresholds. +* @param toolTypeArray Pointer to the array of tool types for which thresholds are set. +* @param distanceArray Pointer to the array of minimum movement distances. +* @return Returns the result code. +* Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. +* Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. +* Returns {@link ARKUI_ERROR_CODE_RECOGNIZER_TYPE_NOT_SUPPORTED} if the gesture recognizer type is +* not supported. +* @since 18 +*/ +ArkUI_ErrorCode OH_ArkUI_PanGesture_SetDistanceMap( + ArkUI_GestureRecognizer* recognizer, int size, int* toolTypeArray, double* distanceArray); + +/** +* @brief Obtains the movement threshold for gestures to be recognized by a gesture recognizer for a specific tool type. +* +* @param recognizer Indicates the pointer to a gesture recognizer. +* @param toolType Tool type for which you want to obtain the threshold. +* @param distance Gesture movement threshold of the gesture recognizer. +* @return Returns the result code. +* Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. +* Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter exception occurs. +* Returns {@link ARKUI_ERROR_CODE_RECOGNIZER_TYPE_NOT_SUPPORTED} if the gesture recognizer type is +* not supported. +* @since 18 +*/ +ArkUI_ErrorCode OH_ArkUI_PanGesture_GetDistanceByToolType( + ArkUI_GestureRecognizer* recognizer, int toolType, double* distance); + ArkUI_NodeHandle OH_ArkUI_GestureEvent_GetNode(const ArkUI_GestureEvent* event); /** * @brief Defines the gesture APIs. diff --git a/interfaces/native/node/gesture_impl.cpp b/interfaces/native/node/gesture_impl.cpp index ed591a9d09fb0b3ff2a960c0dd6c54bfce0543e2..9d236291767c002d49e720ce414aff8ffc5395ad 100644 --- a/interfaces/native/node/gesture_impl.cpp +++ b/interfaces/native/node/gesture_impl.cpp @@ -650,6 +650,46 @@ int32_t OH_ArkUI_GetGestureParam_distanceThreshold(ArkUI_GestureRecognizer* reco return ARKUI_ERROR_CODE_RECOGNIZER_TYPE_NOT_SUPPORTED; } +ArkUI_ErrorCode OH_ArkUI_PanGesture_SetDistanceMap( + ArkUI_GestureRecognizer* recognizer, int size, int* toolTypeArray, double* distanceArray) +{ + if (!recognizer || !toolTypeArray || !distanceArray) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* gesture = reinterpret_cast(recognizer->gesture); + if (!gesture) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + if (recognizer->type == PAN_GESTURE) { + auto result = OHOS::Ace::NodeModel::GetFullImpl() + ->getNodeModifiers() + ->getGestureModifier() + ->setDistanceMap(gesture, size, toolTypeArray, distanceArray); + return static_cast(result); + } + return ARKUI_ERROR_CODE_RECOGNIZER_TYPE_NOT_SUPPORTED; +} + +ArkUI_ErrorCode OH_ArkUI_PanGesture_GetDistanceByToolType( + ArkUI_GestureRecognizer* recognizer, int toolType, double* distance) +{ + if (!recognizer || !distance) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto* gestureRecognizer = reinterpret_cast(recognizer); + if (!gestureRecognizer) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + if (recognizer->type == PAN_GESTURE) { + auto result = OHOS::Ace::NodeModel::GetFullImpl() + ->getNodeModifiers() + ->getGestureModifier() + ->getDistanceByToolType(gestureRecognizer, toolType, distance); + return static_cast(result); + } + return ARKUI_ERROR_CODE_RECOGNIZER_TYPE_NOT_SUPPORTED; +} + namespace OHOS::Ace::GestureModel { constexpr int32_t DEFAULT_PAN_FINGERS = 1;