mirror of
https://github.com/openharmony/ace_engine_lite.git
synced 2026-07-20 05:43:59 -04:00
issueNo: I4DVKW
Description:refactor event listener Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: youzhi92 <chenyouzhi@huawei.com> Change-Id: I17c89be34cd82bfd92e9b34c6e19f603b44f4f04
This commit is contained in:
@@ -52,7 +52,6 @@ void CallbackExecutor(void *data)
|
||||
JSValue args[argsLength] = {params->arg};
|
||||
JSRelease(JSFunction::Call(params->fn, params->vm, args, argsLength));
|
||||
JSRelease(params->arg);
|
||||
JSRelease(params->vm);
|
||||
delete params;
|
||||
params = nullptr;
|
||||
}
|
||||
@@ -127,7 +126,6 @@ void EventUtil::InvokeCallback(JSValue vm, JSValue callback, JSValue event, cons
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "EventUtil::InvokeCallback failed: Async task dispatch failure.");
|
||||
delete params;
|
||||
params = nullptr;
|
||||
JSRelease(vm);
|
||||
JSRelease(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1126,7 +1126,7 @@ void Component::ParseAttrs()
|
||||
|
||||
void Component::SetClickEventListener(UIView &view, const jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
onClickListener_ = new ViewOnClickListener(eventFunc, isStopPropagation);
|
||||
onClickListener_ = new ViewOnClickListener(viewModel_, eventFunc, isStopPropagation);
|
||||
if (onClickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "click listener create failed");
|
||||
return;
|
||||
@@ -1205,7 +1205,7 @@ void Component::SetKeyBoardEventListener(jerry_value_t eventFunc, uint16_t event
|
||||
|
||||
void Component::SetLongPressEventListener(UIView &view, const jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
onLongPressListener_ = new ViewOnLongPressListener(eventFunc, isStopPropagation);
|
||||
onLongPressListener_ = new ViewOnLongPressListener(viewModel_, eventFunc, isStopPropagation);
|
||||
if (onLongPressListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "long press listener create failed");
|
||||
return;
|
||||
@@ -1217,7 +1217,7 @@ void Component::SetLongPressEventListener(UIView &view, const jerry_value_t even
|
||||
|
||||
void Component::SetSwipeEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
onSwipeListener_ = new ViewOnSwipeListener(eventFunc, isStopPropagation);
|
||||
onSwipeListener_ = new ViewOnSwipeListener(viewModel_, eventFunc, isStopPropagation);
|
||||
if (onSwipeListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "swipe listener create failed");
|
||||
return;
|
||||
|
||||
@@ -146,8 +146,7 @@ bool ViewOnSwipeListener::OnDragEnd(UIView& view, const DragEvent &event)
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDragEnd received");
|
||||
|
||||
JSValue arg = EventUtil::CreateSwipeEvent(view, event);
|
||||
JSValue vm = GetRootAbilitySlice();
|
||||
EventUtil::InvokeCallback(vm, fn_, arg, this);
|
||||
EventUtil::InvokeCallback(vm_, fn_, arg, this);
|
||||
return isStopPropagation_;
|
||||
}
|
||||
} // namespace ACELite
|
||||
|
||||
@@ -87,14 +87,16 @@ class ViewOnClickListener final : public UIView::OnClickListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnClickListener);
|
||||
|
||||
ViewOnClickListener(jerry_value_t fn, bool isStopPropagation)
|
||||
ViewOnClickListener(jerry_value_t vm, jerry_value_t fn, bool isStopPropagation)
|
||||
: changeListener_(nullptr),
|
||||
vm_(jerry_acquire_value(vm)),
|
||||
fn_(jerry_acquire_value(fn)),
|
||||
isStopPropagation_(isStopPropagation) {}
|
||||
|
||||
~ViewOnClickListener()
|
||||
{
|
||||
AsyncTaskManager::GetInstance().CancelWithContext(this);
|
||||
jerry_release_value(vm_);
|
||||
jerry_release_value(fn_);
|
||||
}
|
||||
|
||||
@@ -108,8 +110,7 @@ public:
|
||||
return isStopPropagation_;
|
||||
}
|
||||
JSValue arg = EventUtil::CreateEvent(EventUtil::EVENT_CLICK, view, event);
|
||||
JSValue vm = GetRootAbilitySlice();
|
||||
EventUtil::InvokeCallback(vm, fn_, arg, this);
|
||||
EventUtil::InvokeCallback(vm_, fn_, arg, this);
|
||||
|
||||
return isStopPropagation_;
|
||||
}
|
||||
@@ -121,6 +122,7 @@ public:
|
||||
|
||||
private:
|
||||
StateChangeListener *changeListener_;
|
||||
jerry_value_t vm_;
|
||||
jerry_value_t fn_;
|
||||
bool isStopPropagation_;
|
||||
};
|
||||
@@ -128,12 +130,13 @@ private:
|
||||
class ViewOnLongPressListener final : public UIView::OnLongPressListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnLongPressListener);
|
||||
ViewOnLongPressListener(jerry_value_t fn, bool isStopPropagation)
|
||||
: fn_(jerry_acquire_value(fn)), isStopPropagation_(isStopPropagation) {}
|
||||
ViewOnLongPressListener(jerry_value_t vm, jerry_value_t fn, bool isStopPropagation)
|
||||
: vm_(jerry_acquire_value(vm)), fn_(jerry_acquire_value(fn)), isStopPropagation_(isStopPropagation) {}
|
||||
|
||||
~ViewOnLongPressListener()
|
||||
{
|
||||
AsyncTaskManager::GetInstance().CancelWithContext(this);
|
||||
jerry_release_value(vm_);
|
||||
jerry_release_value(fn_);
|
||||
}
|
||||
|
||||
@@ -144,12 +147,12 @@ public:
|
||||
}
|
||||
|
||||
JSValue arg = EventUtil::CreateEvent(EventUtil::EVENT_LONGPRESS, view, event);
|
||||
JSValue vm = GetRootAbilitySlice();
|
||||
EventUtil::InvokeCallback(vm, fn_, arg, this);
|
||||
EventUtil::InvokeCallback(vm_, fn_, arg, this);
|
||||
|
||||
return isStopPropagation_;
|
||||
}
|
||||
jerry_value_t fn_;
|
||||
jerry_value_t vm_;
|
||||
bool isStopPropagation_;
|
||||
};
|
||||
|
||||
@@ -218,14 +221,15 @@ private:
|
||||
class ViewOnSwipeListener final : public UIView::OnDragListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnSwipeListener);
|
||||
ViewOnSwipeListener(jerry_value_t fn, bool isStopPropagation)
|
||||
: fn_(jerry_acquire_value(fn)), isStopPropagation_(isStopPropagation)
|
||||
ViewOnSwipeListener(jerry_value_t vm, jerry_value_t fn, bool isStopPropagation)
|
||||
: vm_(vm), fn_(jerry_acquire_value(fn)), isStopPropagation_(isStopPropagation)
|
||||
{
|
||||
}
|
||||
|
||||
~ViewOnSwipeListener()
|
||||
{
|
||||
AsyncTaskManager::GetInstance().CancelWithContext(this);
|
||||
jerry_release_value(vm_);
|
||||
jerry_release_value(fn_);
|
||||
}
|
||||
|
||||
@@ -235,6 +239,7 @@ public:
|
||||
bool OnDragEnd(UIView& view, const DragEvent &event) override;
|
||||
|
||||
private:
|
||||
jerry_value_t vm_;
|
||||
jerry_value_t fn_;
|
||||
bool isStopPropagation_;
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ bool InputCheckboxComponent::RegisterPrivateEventListener(uint16_t eventTypeId,
|
||||
return true;
|
||||
}
|
||||
if (eventTypeId == K_CLICK) {
|
||||
clickListener_ = new ViewOnClickListener(funcValue, isStopPropagation);
|
||||
clickListener_ = new ViewOnClickListener(GetViewModel(), funcValue, isStopPropagation);
|
||||
if (clickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "create click listener failed");
|
||||
return false;
|
||||
@@ -116,7 +116,7 @@ void InputCheckboxComponent::DealEvent()
|
||||
|
||||
if (clickListener_ == nullptr) {
|
||||
// trigger changeEvent
|
||||
clickListener_ = new ViewOnClickListener(UNDEFINED, true);
|
||||
clickListener_ = new ViewOnClickListener(GetViewModel(), UNDEFINED, true);
|
||||
if (clickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "create click listener failed");
|
||||
return;
|
||||
|
||||
@@ -81,7 +81,7 @@ bool InputRadioComponent::RegisterPrivateEventListener(uint16_t eventTypeId,
|
||||
return true;
|
||||
}
|
||||
if (eventTypeId == K_CLICK) {
|
||||
clickListener_ = new ViewOnClickListener(funcValue, isStopPropagation);
|
||||
clickListener_ = new ViewOnClickListener(GetViewModel(), funcValue, isStopPropagation);
|
||||
if (clickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "create click listener failed");
|
||||
return false;
|
||||
@@ -127,7 +127,7 @@ void InputRadioComponent::DealEvent()
|
||||
|
||||
if (clickListener_ == nullptr) {
|
||||
// trigger changeEvent
|
||||
clickListener_ = new ViewOnClickListener(UNDEFINED, true);
|
||||
clickListener_ = new ViewOnClickListener(GetViewModel(), UNDEFINED, true);
|
||||
if (clickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "create click listener failed");
|
||||
return;
|
||||
|
||||
@@ -99,7 +99,7 @@ bool SwitchComponent::RegisterPrivateEventListener(uint16_t eventTypeId,
|
||||
return true;
|
||||
}
|
||||
if (eventTypeId == K_CLICK) {
|
||||
clickListener_ = new ViewOnClickListener(funcValue, isStopPropagation);
|
||||
clickListener_ = new ViewOnClickListener(GetViewModel(), funcValue, isStopPropagation);
|
||||
if (clickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "create click listener failed");
|
||||
return false;
|
||||
@@ -117,7 +117,7 @@ void SwitchComponent::PostRender()
|
||||
toggleButton_.SetOnChangeListener(changeListener_);
|
||||
if (clickListener_ == nullptr) {
|
||||
// trigger changeEvent
|
||||
clickListener_ = new ViewOnClickListener(UNDEFINED, true);
|
||||
clickListener_ = new ViewOnClickListener(GetViewModel(), UNDEFINED, true);
|
||||
if (clickListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "create click listener failed");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user