mirror of
https://github.com/openharmony/ace_engine_lite.git
synced 2026-07-19 21:33:33 -04:00
Description:【2.2Beta2_挑单】添加对touchStart、touchMove、touchEnd、scrollTop、scrollBottom事件的支持
Sig:ace_engine_lite Feature or Bugfix:Feature Binary Source:No Signed-off-by: lancer <haoshuo@huawei.com>
This commit is contained in:
@@ -33,6 +33,7 @@ constexpr char ATTR_DIRECTION_DOWN[] = "down";
|
||||
const char *EventUtil::EVENT_CLICK = "click";
|
||||
const char *EventUtil::EVENT_LONGPRESS = "longpress";
|
||||
const char *EventUtil::EVENT_SWIPE = "swipe";
|
||||
const char *EventUtil::EVENT_TOUCH = "touch";
|
||||
|
||||
void CallbackExecutor(void *data)
|
||||
{
|
||||
@@ -109,6 +110,14 @@ JSValue EventUtil::CreateSwipeEvent(UIView &view, const DragEvent &event)
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
JSValue EventUtil::CreateTouchEvent(UIView &view, const DragEvent &event)
|
||||
{
|
||||
// create a JAVASCRIPT plain object that is used as the input parameter of
|
||||
// the event callback function.
|
||||
JSValue arg = EventUtil::CreateEvent(EVENT_TOUCH, view, event);
|
||||
|
||||
return arg;
|
||||
}
|
||||
void EventUtil::InvokeCallback(JSValue vm, JSValue callback, JSValue event, const void *context)
|
||||
{
|
||||
auto *params = new CallbackParams();
|
||||
|
||||
@@ -43,6 +43,12 @@ public:
|
||||
*/
|
||||
static JSValue CreateSwipeEvent(UIView &view, const DragEvent &event);
|
||||
|
||||
/**
|
||||
* @brief Create a JAVASCRIPT plain object that is used as the input parameter of
|
||||
* the callback function for touch event.
|
||||
*/
|
||||
static JSValue CreateTouchEvent(UIView &view, const DragEvent &event);
|
||||
|
||||
/**
|
||||
* @brief Invoke the callback function of event.
|
||||
*/
|
||||
@@ -51,6 +57,7 @@ public:
|
||||
static const char *EVENT_CLICK;
|
||||
static const char *EVENT_LONGPRESS;
|
||||
static const char *EVENT_SWIPE;
|
||||
static const char *EVENT_TOUCH;
|
||||
|
||||
private:
|
||||
EventUtil() {}
|
||||
|
||||
@@ -313,7 +313,7 @@ jerry_value_t CallJSWatcher(jerry_value_t arg1,
|
||||
return watcher;
|
||||
}
|
||||
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
bool CallBaseEvent(const jerry_value_t func, const Event &event, const uint16_t id)
|
||||
{
|
||||
if (!jerry_value_is_function(func)) {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "handler.h"
|
||||
#include "js_config.h"
|
||||
#include "non_copyable.h"
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
#include "root_view.h"
|
||||
#endif
|
||||
#include "graphic_config.h"
|
||||
@@ -267,7 +267,7 @@ jerry_value_t ListForWatcherCallbackFunc(const jerry_value_t func,
|
||||
const jerry_value_t context,
|
||||
const jerry_value_t *args,
|
||||
const jerry_length_t argsLength);
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
jerry_value_t *ConvertBaseEventInfo(const Event &event, const uint16_t id);
|
||||
bool CallBaseEvent(const jerry_value_t func, const Event &event, const uint16_t id);
|
||||
jerry_value_t *ConvertDragEventInfo(const DragEvent &event, const uint16_t id);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "key_parser.h"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include "acelite_config.h"
|
||||
#include "js_config.h"
|
||||
#include "keys.h"
|
||||
@@ -346,7 +346,7 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
|
||||
return K_JUSTIFY_CONTENT;
|
||||
}
|
||||
break;
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
case 'k':
|
||||
if (!strcmp(s, "ey")) {
|
||||
return K_KEY;
|
||||
@@ -551,6 +551,12 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
|
||||
if (!strcmp(s, "crollstart")) {
|
||||
return K_SCROLLSTART;
|
||||
}
|
||||
if (!strcmp(s, "crolltop")) {
|
||||
return K_SCROLLTOP;
|
||||
}
|
||||
if (!strcmp(s, "crollbottom")) {
|
||||
return K_SCROLLBOTTOM;
|
||||
}
|
||||
#ifdef FEATURE_COMPONENT_ANALOG_CLOCK
|
||||
if (!strcmp(s, "ec")) {
|
||||
return K_SEC;
|
||||
@@ -660,10 +666,6 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
|
||||
if (!strcmp(s, "otalAngle")) {
|
||||
return K_TOTAL_ANGLE;
|
||||
}
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
if (!strcmp(s, "ouchcancel")) {
|
||||
return K_TOUCHCANCEL;
|
||||
}
|
||||
if (!strcmp(s, "ouchend")) {
|
||||
return K_TOUCHEND;
|
||||
}
|
||||
@@ -673,6 +675,10 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
|
||||
if (!strcmp(s, "ouchstart")) {
|
||||
return K_TOUCHSTART;
|
||||
}
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
if (!strcmp(s, "ouchcancel")) {
|
||||
return K_TOUCHCANCEL;
|
||||
}
|
||||
#endif
|
||||
if (!strcmp(s, "ext")) {
|
||||
return K_TEXT;
|
||||
|
||||
@@ -143,7 +143,7 @@ enum {
|
||||
KEYWORD(ITEM_SELECTED, itemselected) // scroll item selected event listener
|
||||
KEYWORD(ITERATION, iteration) // image-animator attribute
|
||||
KEYWORD(JUSTIFY_CONTENT, justifyContent) // layout style
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
KEYWORD(KEY, key) // onkey event
|
||||
#endif
|
||||
KEYWORD(LABELS, labels) // chart labels
|
||||
@@ -212,9 +212,11 @@ enum {
|
||||
KEYWORD(ROW, row) // layout style
|
||||
KEYWORD(ROW_REVERSE, row-reverse) // layout style
|
||||
KEYWORD(SCROLLAMOUNT, scrollamount) // marquee scroll speed
|
||||
KEYWORD(SCROLLBOTTOM, scrollbottom) // scroll bottom event listener
|
||||
KEYWORD(SCROLLDELAY, scrolldelay) // marquee scroll delay
|
||||
KEYWORD(SCROLLEND, scrollend) // scroll end event listener
|
||||
KEYWORD(SCROLLSTART, scrollstart) // scroll start event listener
|
||||
KEYWORD(SCROLLTOP, scrolltop) // scroll top event listener
|
||||
#ifdef FEATURE_COMPONENT_ANALOG_CLOCK
|
||||
KEYWORD(SEC, sec) // analog-clock second
|
||||
#endif // FEATURE_COMPONENT_ANALOG_CLOCK
|
||||
@@ -264,11 +266,11 @@ enum {
|
||||
#endif // FEATURE_COMPONENT_VIDEO
|
||||
KEYWORD(TOP, top)
|
||||
KEYWORD(TOTAL_ANGLE, total-angle) // circle progress style
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
KEYWORD(TOUCHSTART, touchStart) // touch event listener
|
||||
KEYWORD(TOUCHMOVE, touchmove) // touchmove event listener
|
||||
KEYWORD(TOUCHEND, touchEnd) // touchend event listener
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
KEYWORD(TOUCHCANCEL, touchcancel) // ontouchcancel event
|
||||
KEYWORD(TOUCHEND, touchend) // ontouchend event
|
||||
KEYWORD(TOUCHMOVE, touchmove) // ontouchmove event
|
||||
KEYWORD(TOUCHSTART, touchstart) // ontouchstart event
|
||||
#endif
|
||||
KEYWORD(TRANSLATE_X, translateX) // animation transform x
|
||||
KEYWORD(TRANSLATE_Y, translateY) // animation transform y
|
||||
|
||||
@@ -71,12 +71,9 @@ Component::Component(jerry_value_t options, jerry_value_t children, AppStyleMana
|
||||
children_(UNDEFINED),
|
||||
onClickListener_(nullptr),
|
||||
onLongPressListener_(nullptr),
|
||||
onSwipeListener_(nullptr),
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
onTouchStartListener_(nullptr),
|
||||
onTouchMoveListener_(nullptr),
|
||||
onTouchListener_(nullptr),
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
onTouchCancelListener_(nullptr),
|
||||
onTouchEndListener_(nullptr),
|
||||
keyBoardEventListener_(nullptr),
|
||||
#endif
|
||||
viewId_(nullptr),
|
||||
@@ -424,8 +421,8 @@ void Component::AlignDimensions(const ConstrainedParameter ¶m)
|
||||
|
||||
void Component::EnableTransmitSwipe()
|
||||
{
|
||||
if (onSwipeListener_ != nullptr) {
|
||||
onSwipeListener_->SetStopPropagation(false);
|
||||
if (onTouchListener_ != nullptr) {
|
||||
onTouchListener_->SetStopPropagation(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1135,32 +1132,7 @@ void Component::SetClickEventListener(UIView &view, const jerry_value_t eventFun
|
||||
view.SetTouchable(true);
|
||||
}
|
||||
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
void Component::SetTouchStartEventListener(UIView &view, jerry_value_t eventFunc, uint16_t eventTypeId)
|
||||
{
|
||||
onTouchStartListener_ = new ViewOnTouchStartListener(eventFunc, eventTypeId);
|
||||
if (onTouchStartListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "touch move event listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnTouchListener(onTouchStartListener_);
|
||||
view.SetTouchable(true);
|
||||
}
|
||||
|
||||
void Component::SetTouchMoveEventListener(UIView &view, jerry_value_t eventFunc, uint16_t eventTypeId)
|
||||
{
|
||||
onTouchMoveListener_ = new ViewOnTouchMoveListener(eventFunc, eventTypeId);
|
||||
if (onTouchMoveListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "touch start event listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnDragListener(onTouchMoveListener_);
|
||||
view.SetTouchable(true);
|
||||
view.SetDraggable(true);
|
||||
}
|
||||
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
void Component::SetTouchCancelEventListener(UIView &view, jerry_value_t eventFunc, uint16_t eventTypeId)
|
||||
{
|
||||
onTouchCancelListener_ = new ViewOnTouchCancelListener(eventFunc, eventTypeId);
|
||||
@@ -1174,18 +1146,6 @@ void Component::SetTouchCancelEventListener(UIView &view, jerry_value_t eventFun
|
||||
view.SetDraggable(true);
|
||||
}
|
||||
|
||||
void Component::SetTouchEndEventListener(UIView &view, jerry_value_t eventFunc, uint16_t eventTypeId)
|
||||
{
|
||||
onTouchEndListener_ = new ViewOnTouchEndListener(eventFunc, eventTypeId);
|
||||
if (onTouchEndListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "touch end event listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnTouchListener(onTouchEndListener_);
|
||||
view.SetTouchable(true);
|
||||
}
|
||||
|
||||
void Component::SetKeyBoardEventListener(jerry_value_t eventFunc, uint16_t eventTypeId)
|
||||
{
|
||||
RootView *rootView = RootView::GetInstance();
|
||||
@@ -1216,15 +1176,67 @@ void Component::SetLongPressEventListener(UIView &view, const jerry_value_t even
|
||||
|
||||
void Component::SetSwipeEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
onSwipeListener_ = new ViewOnSwipeListener(viewModel_, eventFunc, isStopPropagation);
|
||||
if (onSwipeListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "swipe listener create failed");
|
||||
if (onTouchListener_ == nullptr)
|
||||
onTouchListener_ = new ViewOnTouchListener(viewModel_, isStopPropagation);
|
||||
if (onTouchListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "DragEnd listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnDragListener(onSwipeListener_);
|
||||
view.SetOnDragListener(onTouchListener_);
|
||||
view.SetDraggable(true);
|
||||
view.SetTouchable(true);
|
||||
|
||||
onTouchListener_->SetBindSwipeFuncName(eventFunc);
|
||||
}
|
||||
|
||||
void Component::SetTouchStartEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
if (onTouchListener_ == nullptr)
|
||||
onTouchListener_ = new ViewOnTouchListener(viewModel_, isStopPropagation);
|
||||
if (onTouchListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "DragStart listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnDragListener(onTouchListener_);
|
||||
|
||||
view.SetDraggable(true);
|
||||
view.SetTouchable(true);
|
||||
|
||||
onTouchListener_->SetBindTouchStartFuncName(eventFunc);
|
||||
}
|
||||
|
||||
void Component::SetTouchMoveEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
if (onTouchListener_ == nullptr)
|
||||
onTouchListener_ = new ViewOnTouchListener(viewModel_, isStopPropagation);
|
||||
if (onTouchListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "Drag listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnDragListener(onTouchListener_);
|
||||
view.SetDraggable(true);
|
||||
view.SetTouchable(true);
|
||||
|
||||
onTouchListener_->SetBindTouchMoveFuncName(eventFunc);
|
||||
}
|
||||
|
||||
void Component::SetTouchEndEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation)
|
||||
{
|
||||
if (onTouchListener_ == nullptr)
|
||||
onTouchListener_ = new ViewOnTouchListener(viewModel_, isStopPropagation);
|
||||
if (onTouchListener_ == nullptr) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "DragEnd listener create failed");
|
||||
return;
|
||||
}
|
||||
|
||||
view.SetOnDragListener(onTouchListener_);
|
||||
view.SetDraggable(true);
|
||||
view.SetTouchable(true);
|
||||
|
||||
onTouchListener_->SetBindTouchEndFuncName(eventFunc);
|
||||
}
|
||||
|
||||
// default implementation
|
||||
@@ -1267,27 +1279,28 @@ bool Component::RegisterCommonEventListener(UIView &view,
|
||||
SetSwipeEventListener(view, funcValue, isStopPropagation);
|
||||
break;
|
||||
}
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
case K_TOUCHSTART: {
|
||||
SetTouchStartEventListener(view, funcValue, isStopPropagation);
|
||||
break;
|
||||
}
|
||||
case K_TOUCHMOVE: {
|
||||
SetTouchMoveEventListener(view, funcValue, isStopPropagation);
|
||||
break;
|
||||
}
|
||||
case K_TOUCHEND: {
|
||||
SetTouchEndEventListener(view, funcValue, isStopPropagation);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
case K_KEY: {
|
||||
SetKeyBoardEventListener(funcValue, eventTypeId);
|
||||
break;
|
||||
}
|
||||
case K_TOUCHSTART: {
|
||||
SetTouchStartEventListener(view, funcValue, eventTypeId);
|
||||
break;
|
||||
}
|
||||
case K_TOUCHCANCEL: {
|
||||
SetTouchCancelEventListener(view, funcValue, eventTypeId);
|
||||
break;
|
||||
}
|
||||
case K_TOUCHMOVE: {
|
||||
SetTouchMoveEventListener(view, funcValue, eventTypeId);
|
||||
break;
|
||||
}
|
||||
case K_TOUCHEND: {
|
||||
SetTouchEndEventListener(view, funcValue, eventTypeId);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
return false;
|
||||
@@ -1300,14 +1313,11 @@ void Component::ReleaseCommonEventListeners()
|
||||
{
|
||||
ACE_DELETE(onClickListener_);
|
||||
ACE_DELETE(onLongPressListener_);
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
ACE_DELETE(keyBoardEventListener_);
|
||||
ACE_DELETE(onTouchStartListener_);
|
||||
ACE_DELETE(onTouchCancelListener_);
|
||||
ACE_DELETE(onTouchMoveListener_);
|
||||
ACE_DELETE(onTouchEndListener_);
|
||||
#endif
|
||||
ACE_DELETE(onSwipeListener_);
|
||||
ACE_DELETE(onTouchListener_);
|
||||
}
|
||||
|
||||
void Component::AppendDescriptorOrElements(Component *parent, const JSValue descriptorOrElements)
|
||||
|
||||
@@ -535,10 +535,10 @@ private:
|
||||
void SetClickEventListener(UIView& view, const jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetLongPressEventListener(UIView& view, const jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetSwipeEventListener(UIView& view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
void SetTouchStartEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetTouchMoveEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetTouchEndEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetTouchStartEventListener(UIView& view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetTouchMoveEventListener(UIView& view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetTouchEndEventListener(UIView& view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
void SetTouchCancelEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation);
|
||||
void SetKeyBoardEventListener(jerry_value_t eventFunc, bool isStopPropagation);
|
||||
#endif
|
||||
@@ -613,12 +613,9 @@ private:
|
||||
jerry_value_t children_;
|
||||
ViewOnClickListener *onClickListener_;
|
||||
ViewOnLongPressListener *onLongPressListener_;
|
||||
ViewOnSwipeListener *onSwipeListener_;
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
ViewOnTouchStartListener *onTouchStartListener_;
|
||||
ViewOnTouchMoveListener *onTouchMoveListener_;
|
||||
ViewOnTouchListener *onTouchListener_;
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
ViewOnTouchCancelListener *onTouchCancelListener_;
|
||||
ViewOnTouchEndListener *onTouchEndListener_;
|
||||
KeyBoardEventListener *keyBoardEventListener_;
|
||||
#endif
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace ACELite {
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
KeyBoardEventListener::KeyBoardEventListener(jerry_value_t fn, const uint16_t id)
|
||||
{
|
||||
fn_ = jerry_acquire_value(fn);
|
||||
@@ -44,61 +44,6 @@ bool KeyBoardEventListener::OnKeyAct(UIView &view, const KeyEvent &event)
|
||||
return true;
|
||||
}
|
||||
|
||||
ViewOnTouchStartListener::ViewOnTouchStartListener(jerry_value_t fn, uint16_t id)
|
||||
{
|
||||
fn_ = jerry_acquire_value(fn);
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
ViewOnTouchStartListener::~ViewOnTouchStartListener()
|
||||
{
|
||||
jerry_release_value(fn_);
|
||||
}
|
||||
|
||||
bool ViewOnTouchStartListener::OnPress(UIView &view, const PressEvent &event)
|
||||
{
|
||||
return CallBaseEvent(fn_, event, id_);
|
||||
}
|
||||
|
||||
ViewOnTouchMoveListener::ViewOnTouchMoveListener(jerry_value_t fn, uint16_t id)
|
||||
{
|
||||
fn_ = jerry_acquire_value(fn);
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
ViewOnTouchMoveListener::~ViewOnTouchMoveListener()
|
||||
{
|
||||
jerry_release_value(fn_);
|
||||
}
|
||||
|
||||
bool ViewOnTouchMoveListener::OnDrag(UIView &view, const DragEvent &event)
|
||||
{
|
||||
if (jerry_value_is_undefined(fn_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jerry_value_t *args = ConvertDragEventInfo(event, id_);
|
||||
jerry_release_value(CallJSFunctionOnRoot(fn_, args, 1));
|
||||
ClearEventListener(args, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
ViewOnTouchEndListener::ViewOnTouchEndListener(jerry_value_t fn, uint16_t id)
|
||||
{
|
||||
fn_ = jerry_acquire_value(fn);
|
||||
id_ = id;
|
||||
}
|
||||
|
||||
ViewOnTouchEndListener::~ViewOnTouchEndListener()
|
||||
{
|
||||
jerry_release_value(fn_);
|
||||
}
|
||||
|
||||
bool ViewOnTouchEndListener::OnRelease(UIView &view, const ReleaseEvent &event)
|
||||
{
|
||||
return CallBaseEvent(fn_, event, id_);
|
||||
}
|
||||
|
||||
ViewOnTouchCancelListener::ViewOnTouchCancelListener(jerry_value_t fn, uint16_t id)
|
||||
{
|
||||
fn_ = jerry_acquire_value(fn);
|
||||
@@ -113,40 +58,84 @@ bool ViewOnTouchCancelListener::OnCancel(UIView &view, const CancelEvent &event)
|
||||
{
|
||||
return CallBaseEvent(fn_, event, id_);
|
||||
}
|
||||
#endif // JS_TOUCH_EVENT_SUPPORT
|
||||
#endif // JS_EXTRA_EVENT_SUPPORT
|
||||
|
||||
void ViewOnSwipeListener::SetStopPropagation(bool isStopPropogation)
|
||||
void ViewOnTouchListener::SetBindTouchStartFuncName(jerry_value_t bindTouchStartFunc)
|
||||
{
|
||||
if (!jerry_value_is_undefined(bindTouchStartFunc)) {
|
||||
bindTouchStartFunc_ = jerry_acquire_value(bindTouchStartFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewOnTouchListener::SetBindTouchMoveFuncName(jerry_value_t bindTouchMoveFunc)
|
||||
{
|
||||
if (!jerry_value_is_undefined(bindTouchMoveFunc)) {
|
||||
bindTouchMoveFunc_ = jerry_acquire_value(bindTouchMoveFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ViewOnTouchListener::SetBindTouchEndFuncName(jerry_value_t bindTouchEndFunc)
|
||||
{
|
||||
if (!jerry_value_is_undefined(bindTouchEndFunc)) {
|
||||
bindTouchEndFunc_ = jerry_acquire_value(bindTouchEndFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewOnTouchListener::SetBindSwipeFuncName(jerry_value_t bindSwipeFunc)
|
||||
{
|
||||
if (!jerry_value_is_undefined(bindSwipeFunc)) {
|
||||
bindSwipeFunc_ = jerry_acquire_value(bindSwipeFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewOnTouchListener::SetStopPropagation(bool isStopPropogation)
|
||||
{
|
||||
isStopPropagation_ = isStopPropogation;
|
||||
}
|
||||
|
||||
bool ViewOnSwipeListener::OnDragStart(UIView& view, const DragEvent &event)
|
||||
bool ViewOnTouchListener::OnDragStart(UIView& view, const DragEvent &event)
|
||||
{
|
||||
UNUSED(view);
|
||||
UNUSED(event);
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDragStart received");
|
||||
return isStopPropagation_;
|
||||
}
|
||||
|
||||
bool ViewOnSwipeListener::OnDrag(UIView& view, const DragEvent& event)
|
||||
{
|
||||
UNUSED(view);
|
||||
UNUSED(event);
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDrag received");
|
||||
return isStopPropagation_;
|
||||
}
|
||||
|
||||
bool ViewOnSwipeListener::OnDragEnd(UIView& view, const DragEvent &event)
|
||||
{
|
||||
if (JSUndefined::Is(fn_)) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "OnDragEnd received, but no JS function to call");
|
||||
if (JSUndefined::Is(bindTouchStartFunc_)) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "OnDragStart received, but no JS function to call");
|
||||
return isStopPropagation_;
|
||||
}
|
||||
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDragEnd received");
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDragStart received");
|
||||
|
||||
JSValue arg = EventUtil::CreateSwipeEvent(view, event);
|
||||
EventUtil::InvokeCallback(vm_, fn_, arg, this);
|
||||
JSValue arg = EventUtil::CreateTouchEvent(view, event);
|
||||
EventUtil::InvokeCallback(vm_, bindTouchStartFunc_, arg, this);
|
||||
return isStopPropagation_;
|
||||
}
|
||||
|
||||
bool ViewOnTouchListener::OnDrag(UIView& view, const DragEvent& event)
|
||||
{
|
||||
if (JSUndefined::Is(bindTouchMoveFunc_)) {
|
||||
HILOG_ERROR(HILOG_MODULE_ACE, "OnDrag received, but no JS function to call");
|
||||
return isStopPropagation_;
|
||||
}
|
||||
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDrag received");
|
||||
|
||||
JSValue arg = EventUtil::CreateTouchEvent(view, event);
|
||||
EventUtil::InvokeCallback(vm_, bindTouchMoveFunc_, arg, this);
|
||||
return isStopPropagation_;
|
||||
}
|
||||
|
||||
bool ViewOnTouchListener::OnDragEnd(UIView& view, const DragEvent &event)
|
||||
{
|
||||
if (!JSUndefined::Is(bindSwipeFunc_)) {
|
||||
JSValue argSwipe = EventUtil::CreateSwipeEvent(view, event);
|
||||
EventUtil::InvokeCallback(vm_, bindSwipeFunc_, argSwipe, this);
|
||||
}
|
||||
|
||||
if (!JSUndefined::Is(bindTouchEndFunc_)) {
|
||||
JSValue argDragEnd = EventUtil::CreateTouchEvent(view, event);
|
||||
EventUtil::InvokeCallback(vm_, bindTouchEndFunc_, argDragEnd, this);
|
||||
}
|
||||
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "OnDragEnd received");
|
||||
HILOG_DEBUG(HILOG_MODULE_ACE, "Swipe received");
|
||||
return isStopPropagation_;
|
||||
}
|
||||
} // namespace ACELite
|
||||
|
||||
@@ -156,54 +156,7 @@ public:
|
||||
bool isStopPropagation_;
|
||||
};
|
||||
|
||||
#ifdef JS_TOUCH_EVENT_SUPPORT
|
||||
class ViewOnTouchStartListener final : public UIView::OnTouchListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnTouchStartListener);
|
||||
ViewOnTouchStartListener(jerry_value_t fn, const uint16_t id);
|
||||
~ViewOnTouchStartListener();
|
||||
bool OnPress(UIView &view, const PressEvent &event) override;
|
||||
|
||||
private:
|
||||
jerry_value_t fn_;
|
||||
uint16_t id_;
|
||||
};
|
||||
|
||||
class ViewOnTouchMoveListener final : public UIView::OnDragListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnTouchMoveListener);
|
||||
ViewOnTouchMoveListener(jerry_value_t fn, const uint16_t id);
|
||||
~ViewOnTouchMoveListener();
|
||||
bool OnDrag(UIView &view, const DragEvent &event) override;
|
||||
|
||||
private:
|
||||
jerry_value_t fn_;
|
||||
uint16_t id_;
|
||||
};
|
||||
|
||||
class ViewOnTouchEndListener final : public UIView::OnTouchListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnTouchEndListener);
|
||||
ViewOnTouchEndListener(jerry_value_t fn, const uint16_t id);
|
||||
~ViewOnTouchEndListener();
|
||||
bool OnRelease(UIView &view, const ReleaseEvent &event) override;
|
||||
|
||||
private:
|
||||
jerry_value_t fn_;
|
||||
uint16_t id_;
|
||||
};
|
||||
|
||||
class ViewOnTouchCancelListener final : public UIView::OnTouchListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnTouchCancelListener);
|
||||
ViewOnTouchCancelListener(jerry_value_t fn, const uint16_t id);
|
||||
~ViewOnTouchCancelListener();
|
||||
bool OnCancel(UIView &view, const CancelEvent &event) override;
|
||||
|
||||
private:
|
||||
jerry_value_t fn_;
|
||||
uint16_t id_;
|
||||
};
|
||||
#ifdef JS_EXTRA_EVENT_SUPPORT
|
||||
|
||||
class KeyBoardEventListener final : public RootView::OnKeyActListener {
|
||||
public:
|
||||
@@ -218,29 +171,44 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
class ViewOnSwipeListener final : public UIView::OnDragListener {
|
||||
class ViewOnTouchListener final : public UIView::OnDragListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnSwipeListener);
|
||||
ViewOnSwipeListener(jerry_value_t vm, jerry_value_t fn, bool isStopPropagation)
|
||||
: vm_(jerry_acquire_value(vm)), fn_(jerry_acquire_value(fn)), isStopPropagation_(isStopPropagation)
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ViewOnTouchListener);
|
||||
ViewOnTouchListener(jerry_value_t vm, bool isStopPropagation)
|
||||
: vm_(jerry_acquire_value(vm)),
|
||||
isStopPropagation_(isStopPropagation),
|
||||
bindTouchStartFunc_(UNDEFINED),
|
||||
bindTouchMoveFunc_(UNDEFINED),
|
||||
bindTouchEndFunc_(UNDEFINED),
|
||||
bindSwipeFunc_(UNDEFINED)
|
||||
{
|
||||
}
|
||||
|
||||
~ViewOnSwipeListener()
|
||||
~ViewOnTouchListener()
|
||||
{
|
||||
AsyncTaskManager::GetInstance().CancelWithContext(this);
|
||||
jerry_release_value(vm_);
|
||||
jerry_release_value(fn_);
|
||||
jerry_release_value(bindTouchStartFunc_);
|
||||
jerry_release_value(bindTouchMoveFunc_);
|
||||
jerry_release_value(bindTouchEndFunc_);
|
||||
jerry_release_value(bindSwipeFunc_);
|
||||
}
|
||||
|
||||
void SetStopPropagation(bool isStopPropogation);
|
||||
bool OnDragStart(UIView& view, const DragEvent& event) override;
|
||||
bool OnDrag(UIView& view, const DragEvent& event) override;
|
||||
bool OnDragEnd(UIView& view, const DragEvent &event) override;
|
||||
void SetBindTouchStartFuncName(jerry_value_t bindTouchStartFunc);
|
||||
void SetBindTouchMoveFuncName(jerry_value_t bindTouchMoveFunc);
|
||||
void SetBindTouchEndFuncName(jerry_value_t bindTouchEndFunc);
|
||||
void SetBindSwipeFuncName(jerry_value_t bindSwipeFunc);
|
||||
|
||||
private:
|
||||
jerry_value_t vm_;
|
||||
jerry_value_t fn_;
|
||||
jerry_value_t bindTouchStartFunc_;
|
||||
jerry_value_t bindTouchMoveFunc_;
|
||||
jerry_value_t bindTouchEndFunc_;
|
||||
jerry_value_t bindSwipeFunc_;
|
||||
bool isStopPropagation_;
|
||||
};
|
||||
|
||||
@@ -279,12 +247,17 @@ class ListEventListener final : public ListScrollListener {
|
||||
public:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(ListEventListener);
|
||||
ListEventListener()
|
||||
: bindScrollStartFunc_(UNDEFINED), bindScrollEndFunc_(UNDEFINED), bindScrollSelectedFunc_(UNDEFINED)
|
||||
: bindScrollStartFunc_(UNDEFINED),
|
||||
bindScrollEndFunc_(UNDEFINED),
|
||||
bindScrollSelectedFunc_(UNDEFINED),
|
||||
bindScrollTopFunc_(UNDEFINED),
|
||||
bindScrollBottomFunc_(UNDEFINED)
|
||||
{
|
||||
}
|
||||
~ListEventListener()
|
||||
{
|
||||
ReleaseJerryValue(bindScrollStartFunc_, bindScrollEndFunc_, bindScrollSelectedFunc_, VA_ARG_END_FLAG);
|
||||
ReleaseJerryValue(bindScrollStartFunc_, bindScrollEndFunc_, bindScrollSelectedFunc_, bindScrollTopFunc_,
|
||||
bindScrollBottomFunc_, VA_ARG_END_FLAG);
|
||||
}
|
||||
|
||||
void EventExcute(const int16_t index, jerry_value_t bindScrollFunc) const
|
||||
@@ -337,11 +310,37 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void OnScrollTop(int16_t index, UIView* view) override
|
||||
{
|
||||
EventExcute(index, bindScrollTopFunc_);
|
||||
}
|
||||
|
||||
void SetBindScrollTopFuncName(jerry_value_t bindScrollTopFunc)
|
||||
{
|
||||
if (!jerry_value_is_undefined(bindScrollTopFunc)) {
|
||||
bindScrollTopFunc_ = jerry_acquire_value(bindScrollTopFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void OnScrollBottom(int16_t index, UIView* view) override
|
||||
{
|
||||
EventExcute(index, bindScrollBottomFunc_);
|
||||
}
|
||||
|
||||
void SetBindScrollBottomFuncName(jerry_value_t bindScrollBottomFunc)
|
||||
{
|
||||
if (!jerry_value_is_undefined(bindScrollBottomFunc)) {
|
||||
bindScrollBottomFunc_ = jerry_acquire_value(bindScrollBottomFunc);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int8_t ARGS_LEN = 2;
|
||||
jerry_value_t bindScrollStartFunc_;
|
||||
jerry_value_t bindScrollEndFunc_;
|
||||
jerry_value_t bindScrollSelectedFunc_;
|
||||
jerry_value_t bindScrollTopFunc_;
|
||||
jerry_value_t bindScrollBottomFunc_;
|
||||
};
|
||||
} // namespace ACELite
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -103,6 +103,12 @@ bool ListComponent::RegisterPrivateEventListener(uint16_t eventTypeId, JSValue f
|
||||
case K_SCROLLEND:
|
||||
listEventListener_.SetBindScrollEndFuncName(funcValue);
|
||||
break;
|
||||
case K_SCROLLTOP:
|
||||
listEventListener_.SetBindScrollTopFuncName(funcValue);
|
||||
break;
|
||||
case K_SCROLLBOTTOM:
|
||||
listEventListener_.SetBindScrollBottomFuncName(funcValue);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user