From 285552d8483c11dce27cf0fa00034699639092e4 Mon Sep 17 00:00:00 2001 From: liyi0309 Date: Wed, 24 Apr 2024 15:04:05 +0800 Subject: [PATCH] =?UTF-8?q?NDK=20C-API=20=E6=89=8B=E5=8A=BF=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=20Signed-off-by:=20liyi0309?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/interfaces/arkoala/arkoala_api.h | 2 ++ .../core/interfaces/native/node/node_api.cpp | 7 +++++++ interfaces/native/node/gesture_impl.cpp | 16 ++++++++++++++-- interfaces/native/node/style_modifier.cpp | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 6d5af672b5c..a35a2726703 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -3502,6 +3502,8 @@ struct ArkUIBasicAPI { // the flag can combine different flag like ARKUI_DIRTY_FLAG_MEASURE | ARKUI_DIRTY_FLAG_RENDER void (*markDirty)(ArkUINodeHandle nodePtr, ArkUI_Uint32 dirtyFlag); ArkUI_Bool (*isBuilderNode)(ArkUINodeHandle node); + + ArkUI_Float64 (*convertLengthMetricsUnit)(ArkUI_Float64 value, ArkUI_Int32 originUnit, ArkUI_Int32 targetUnit); }; struct ArkUIDialogAPI { diff --git a/frameworks/core/interfaces/native/node/node_api.cpp b/frameworks/core/interfaces/native/node/node_api.cpp index 392112d3916..8a83f0eaef8 100644 --- a/frameworks/core/interfaces/native/node/node_api.cpp +++ b/frameworks/core/interfaces/native/node/node_api.cpp @@ -207,6 +207,12 @@ ArkUI_Bool IsBuilderNode(ArkUINodeHandle node) return ViewModel::IsBuilderNode(node); } +ArkUI_Float64 ConvertLengthMetricsUnit(ArkUI_Float64 value, ArkUI_Int32 originUnit, ArkUI_Int32 targetUnit) +{ + Dimension lengthMetric(value, static_cast(originUnit)); + return lengthMetric.GetNativeValue(static_cast(targetUnit)); +} + ArkUI_Int32 InsertChildBefore(ArkUINodeHandle parent, ArkUINodeHandle child, ArkUINodeHandle sibling) { auto* nodeAdapter = NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(parent); @@ -822,6 +828,7 @@ const ArkUIBasicAPI* GetBasicAPI() ApplyModifierFinish, MarkDirty, IsBuilderNode, + ConvertLengthMetricsUnit, }; /* clang-format on */ diff --git a/interfaces/native/node/gesture_impl.cpp b/interfaces/native/node/gesture_impl.cpp index a24029e0882..d436d2f5166 100644 --- a/interfaces/native/node/gesture_impl.cpp +++ b/interfaces/native/node/gesture_impl.cpp @@ -132,6 +132,8 @@ namespace OHOS::Ace::GestureModel { constexpr int32_t DEFAULT_PAN_FINGERS = 1; constexpr int32_t MAX_PAN_FINGERS = 10; +constexpr double DEFAULT_PINCH_DISTANCE = 5.0f; +constexpr double DEFAULT_SWIPE_SPEED = 100.0f; struct GestureInnerData { void (*targetReceiver)(ArkUI_GestureEvent* event, void* extraParam); @@ -155,9 +157,14 @@ ArkUI_GestureRecognizer* CreateLongPressGesture(int32_t fingers, bool repeatResu ArkUI_GestureRecognizer* CreatePinchGesture(int32_t fingers, double distance) { + if (LessOrEqual(distance, 0.0f)) { + distance = DEFAULT_PINCH_DISTANCE; + } + double distanceNum = OHOS::Ace::NodeModel::GetFullImpl()->getBasicAPI()->convertLengthMetricsUnit( + distance, static_cast(ARKUI_LENGTH_METRIC_UNIT_PX), static_cast(ARKUI_LENGTH_METRIC_UNIT_VP)); auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createPinchGesture(fingers, - distance); + distanceNum); return new ArkUI_GestureRecognizer{ PINCH_GESTURE, gesture, nullptr }; } @@ -171,9 +178,14 @@ ArkUI_GestureRecognizer* CreateRotationGesture(int32_t fingers, double angle) ArkUI_GestureRecognizer* CreateSwipeGesture(int32_t fingers, ArkUI_GestureDirectionMask directions, double speed) { + if (LessOrEqual(speed, 0.0f)) { + speed = DEFAULT_SWIPE_SPEED; + } + double speedNum = OHOS::Ace::NodeModel::GetFullImpl()->getBasicAPI()->convertLengthMetricsUnit( + speed, static_cast(ARKUI_LENGTH_METRIC_UNIT_PX), static_cast(ARKUI_LENGTH_METRIC_UNIT_VP)); auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createSwipeGesture(fingers, - directions, speed); + directions, speedNum); return new ArkUI_GestureRecognizer{ SWIPE_GESTURE, gesture, nullptr }; } diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index 8f00c5ae17d..8a9bf65e5fa 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -6953,7 +6953,7 @@ int32_t SetSpanTextBackgroundStyle(ArkUI_NodeHandle node, const ArkUI_AttributeI int radiusUnits[ALLOW_SIZE_4] = { unit, unit, unit, unit }; if (item->size == ALLOW_SIZE_2) { - if (LessNotEqual(item->value[0].f32, 0.0f)) { + if (LessNotEqual(item->value[NUM_1].f32, 0.0f)) { return ERROR_CODE_PARAM_INVALID; } for (int i = 0; i < ALLOW_SIZE_4; ++i) { @@ -6964,7 +6964,7 @@ int32_t SetSpanTextBackgroundStyle(ArkUI_NodeHandle node, const ArkUI_AttributeI if (LessNotEqual(item->value[i + NUM_1].f32, 0.0f)) { return ERROR_CODE_PARAM_INVALID; } else { - radiusVals[i + NUM_1] = item->value[i + NUM_1].f32; + radiusVals[i] = item->value[i + NUM_1].f32; } } } else { -- Gitee