NDK c-api fix longpress gesture problem

Signed-off-by: liyi0309<liyi58@huawei.com>

Change-Id: I6412243c90220504fb1d62792689ae88800445ff
This commit is contained in:
firminly 2024-06-02 11:53:24 +08:00
parent dcbdaa3b92
commit 0a7517eb56
7 changed files with 73 additions and 35 deletions

View File

@ -101,6 +101,16 @@ public:
return userData_;
}
void SetDisposeTag(bool tag)
{
disposeTag_ = tag;
}
bool GetDisposeTag()
{
return disposeTag_;
}
private:
std::optional<std::string> tag_;
GestureTypeName type_ = GestureTypeName::UNKNOWN;
@ -109,6 +119,7 @@ private:
InputEventType inputEventType_ = InputEventType::TOUCH_SCREEN;
bool isSystemGesture_ = false;
void* userData_ = nullptr;
bool disposeTag_ = false;
};
} // namespace OHOS::Ace::NG

View File

@ -204,6 +204,13 @@ public:
virtual RefPtr<NGGestureRecognizer> CreateRecognizer() = 0;
void SetDisposeTag(bool tag)
{
if (gestureInfo_) {
gestureInfo_->SetDisposeTag(tag);
}
}
protected:
int32_t fingers_ = 1;
GesturePriority priority_ = GesturePriority::Low;

View File

@ -38,6 +38,9 @@ RefPtr<NGGestureRecognizer> LongPressGesture::CreateRecognizer()
if (onActionCancelId_) {
longPressRecognizer->SetOnActionCancel(*onActionCancelId_);
}
if (gestureInfo_) {
gestureInfo_->SetDisposeTag(false);
}
longPressRecognizer->SetUserData(userData_);
return longPressRecognizer;

View File

@ -344,7 +344,7 @@ double LongPressRecognizer::ConvertPxToVp(double offset) const
void LongPressRecognizer::SendCallbackMsg(
const std::unique_ptr<GestureEventFunc>& callback, bool isRepeat, bool isOnAction)
{
if (callback && *callback) {
if (callback && *callback && !gestureInfo_->GetDisposeTag()) {
GestureEvent info;
info.SetTimeStamp(time_);
info.SetRepeat(isRepeat);

View File

@ -166,6 +166,7 @@ void removeGestureFromGestureGroup(ArkUIGesture* group, ArkUIGesture* child)
void dispose(ArkUIGesture* recognizer)
{
Gesture* gestureRef = reinterpret_cast<Gesture*>(recognizer);
gestureRef->SetDisposeTag(true);
gestureRef->DecRefCount();
}
@ -268,12 +269,12 @@ void GetBaseGestureEvent(ArkUIAPIEventGestureAsyncEvent* ret, ArkUITouchEvent& r
void setCancelActionFunc(Gesture* gestureRef, void* extraParam)
{
auto onActionCancel = [extraParam]() {
ArkUINodeEvent *eventData = new ArkUINodeEvent();
eventData->kind = GESTURE_ASYNC_EVENT;
eventData->nodeId = 0;
eventData->extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData->gestureAsyncEvent.subKind = ON_ACTION_CANCEL;
SendArkUIAsyncEvent(eventData);
ArkUINodeEvent eventData;
eventData.kind = GESTURE_ASYNC_EVENT;
eventData.nodeId = 0;
eventData.extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData.gestureAsyncEvent.subKind = ON_ACTION_CANCEL;
SendArkUIAsyncEvent(&eventData);
};
gestureRef->SetOnActionCancelId(onActionCancel);
}
@ -283,50 +284,50 @@ void registerGestureEvent(ArkUIGesture* gesture, ArkUI_Uint32 actionTypeMask, vo
Gesture* gestureRef = reinterpret_cast<Gesture*>(gesture);
if (actionTypeMask & ARKUI_GESTURE_EVENT_ACTION_ACCEPT) {
auto onActionAccept = [extraParam](GestureEvent& info) {
ArkUINodeEvent *eventData = new ArkUINodeEvent();
eventData->kind = GESTURE_ASYNC_EVENT;
eventData->nodeId = 0;
eventData->extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData->gestureAsyncEvent.subKind = ON_ACTION_START;
GetGestureEvent(eventData->gestureAsyncEvent, info);
ArkUINodeEvent eventData;
eventData.kind = GESTURE_ASYNC_EVENT;
eventData.nodeId = 0;
eventData.extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData.gestureAsyncEvent.subKind = ON_ACTION_START;
GetGestureEvent(eventData.gestureAsyncEvent, info);
ArkUITouchEvent rawInputEvent;
std::array<ArkUITouchPoint, MAX_POINTS> points;
ConvertIMMEventToTouchEvent(info, rawInputEvent, points);
eventData->gestureAsyncEvent.rawPointerEvent = &rawInputEvent;
SendArkUIAsyncEvent(eventData);
eventData.gestureAsyncEvent.rawPointerEvent = &rawInputEvent;
SendArkUIAsyncEvent(&eventData);
};
gestureRef->SetOnActionId(onActionAccept);
gestureRef->SetOnActionStartId(onActionAccept);
}
if (actionTypeMask & ARKUI_GESTURE_EVENT_ACTION_UPDATE) {
auto onActionUpdate = [extraParam](GestureEvent& info) {
ArkUINodeEvent *eventData = new ArkUINodeEvent();
eventData->kind = GESTURE_ASYNC_EVENT;
eventData->nodeId = 0;
eventData->extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData->gestureAsyncEvent.subKind = ON_ACTION_UPDATE;
GetGestureEvent(eventData->gestureAsyncEvent, info);
ArkUINodeEvent eventData;
eventData.kind = GESTURE_ASYNC_EVENT;
eventData.nodeId = 0;
eventData.extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData.gestureAsyncEvent.subKind = ON_ACTION_UPDATE;
GetGestureEvent(eventData.gestureAsyncEvent, info);
ArkUITouchEvent rawInputEvent;
std::array<ArkUITouchPoint, MAX_POINTS> points;
ConvertIMMEventToTouchEvent(info, rawInputEvent, points);
eventData->gestureAsyncEvent.rawPointerEvent = &rawInputEvent;
SendArkUIAsyncEvent(eventData);
eventData.gestureAsyncEvent.rawPointerEvent = &rawInputEvent;
SendArkUIAsyncEvent(&eventData);
};
gestureRef->SetOnActionUpdateId(onActionUpdate);
}
if (actionTypeMask & ARKUI_GESTURE_EVENT_ACTION_END) {
auto onActionEnd = [extraParam](GestureEvent& info) {
ArkUINodeEvent *eventData = new ArkUINodeEvent();
eventData->kind = GESTURE_ASYNC_EVENT;
eventData->nodeId = 0;
eventData->extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData->gestureAsyncEvent.subKind = ON_ACTION_END;
GetGestureEvent(eventData->gestureAsyncEvent, info);
ArkUINodeEvent eventData;
eventData.kind = GESTURE_ASYNC_EVENT;
eventData.nodeId = 0;
eventData.extraParam = reinterpret_cast<ArkUI_Int64>(extraParam);
eventData.gestureAsyncEvent.subKind = ON_ACTION_END;
GetGestureEvent(eventData.gestureAsyncEvent, info);
ArkUITouchEvent rawInputEvent;
std::array<ArkUITouchPoint, MAX_POINTS> points;
ConvertIMMEventToTouchEvent(info, rawInputEvent, points);
eventData->gestureAsyncEvent.rawPointerEvent = &rawInputEvent;
SendArkUIAsyncEvent(eventData);
eventData.gestureAsyncEvent.rawPointerEvent = &rawInputEvent;
SendArkUIAsyncEvent(&eventData);
};
gestureRef->SetOnActionEndId(onActionEnd);
}

View File

@ -258,7 +258,9 @@ void DisposeGesture(ArkUI_GestureRecognizer* recognizer)
{
OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->dispose(recognizer->gesture);
delete reinterpret_cast<GestureInnerData*>(recognizer->extraData);
recognizer->extraData = nullptr;
delete recognizer;
recognizer = nullptr;
}
int32_t SetGestureEventTarget(ArkUI_GestureRecognizer* recognizer, ArkUI_GestureEventActionTypeMask mask,
@ -268,6 +270,7 @@ int32_t SetGestureEventTarget(ArkUI_GestureRecognizer* recognizer, ArkUI_Gesture
// 把回调函数和上下文都封装到内部结构体中。
if (recognizer->extraData) {
delete reinterpret_cast<GestureInnerData*>(recognizer->extraData);
recognizer->extraData = nullptr;
}
recognizer->extraData = new GestureInnerData { targetReceiver, extraParam };
OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->registerGestureEvent(
@ -318,15 +321,23 @@ int32_t RemoveChildGesture(ArkUI_GestureRecognizer* group, ArkUI_GestureRecogniz
void HandleGestureEvent(ArkUINodeEvent* event)
{
if (event == nullptr) {
return;
}
auto* extraData = reinterpret_cast<GestureInnerData*>(event->extraParam);
if (extraData == nullptr) {
return;
}
ArkUI_GestureEvent* gestureEvent = reinterpret_cast<ArkUI_GestureEvent *>(&event->gestureAsyncEvent);
if (gestureEvent == nullptr || extraData->targetReceiver == nullptr) {
return;
}
ArkUI_UIInputEvent uiEvent;
uiEvent.inputType = ARKUI_UIINPUTEVENT_TYPE_TOUCH;
uiEvent.eventTypeId = C_TOUCH_EVENT_ID;
uiEvent.inputEvent = gestureEvent->eventData.rawPointerEvent;
gestureEvent->eventData.rawPointerEvent = &uiEvent;
extraData->targetReceiver(gestureEvent, extraData->extraParam);
delete event;
}
int32_t SetGestureInterrupterToNode(

View File

@ -4089,7 +4089,9 @@ void ResetPlaceholderColor(ArkUI_NodeHandle node)
int32_t SetTextInputPlaceholderFont(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
// already check in entry point.
if (item == nullptr) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
struct ArkUIResourceLength size = { 16.0, GetDefaultUnit(node, UNIT_FP) };
int weight = ARKUI_FONT_WEIGHT_NORMAL;
@ -5593,6 +5595,9 @@ int32_t SetListScrollToIndex(ArkUI_NodeHandle node, const ArkUI_AttributeItem* i
int32_t SetTextAreaPlaceholderFont(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item == nullptr) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
struct ArkUIResourceLength size = { 16.0, GetDefaultUnit(node, UNIT_FP) };
int weight = ARKUI_FONT_WEIGHT_NORMAL;
@ -5813,7 +5818,7 @@ void ResetTextAreaSelectionMenuHidden(ArkUI_NodeHandle node)
// button
int32_t SetButtonLabel(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->string == nullptr) {
if (item == nullptr || item->string == nullptr) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
@ -5970,7 +5975,7 @@ int32_t SetXComponentId(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
// already check in entry point.
auto* fullImpl = GetFullImpl();
if (!item->string) {
if (item == nullptr || !item->string) {
return ERROR_CODE_PARAM_INVALID;
}
fullImpl->getNodeModifiers()->getXComponentModifier()->setXComponentId(node->uiNodeHandle, item->string);