!40906 挑单:在tapGesture中新增distance

Merge pull request !40906 from 郑齐熠/OpenHarmony-5.0-Release
This commit is contained in:
openharmony_ci 2024-08-22 06:27:50 +00:00 committed by Gitee
commit b9c3cc46f0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
31 changed files with 174 additions and 42 deletions

View File

@ -75,6 +75,7 @@ constexpr int32_t BACKWARD_COMPAT_MAGIC_NUMBER_OFFSCREEN = 1000;
constexpr SharedTransitionEffectType DEFAULT_SHARED_EFFECT = SharedTransitionEffectType::SHARED_EFFECT_EXCHANGE;
constexpr int32_t DEFAULT_TAP_FINGER = 1;
constexpr int32_t DEFAULT_TAP_COUNT = 1;
constexpr double DEFAULT_TAP_DISTANCE = std::numeric_limits<double>::infinity();
constexpr int32_t DEFAULT_LONG_PRESS_FINGER = 1;
constexpr int32_t DEFAULT_LONG_PRESS_DURATION = 500;
constexpr int32_t DEFAULT_PINCH_FINGER = 2;
@ -5968,8 +5969,8 @@ void CommonBridge::SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t
}
}
void CommonBridge::GetTapGestureValue(
ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& count, uint32_t argNumber)
void CommonBridge::GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers,
int32_t& count, double& distanceThreshold, uint32_t argNumber)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_VOID(vm);
@ -5984,6 +5985,11 @@ void CommonBridge::GetTapGestureValue(
auto countValue = static_cast<int32_t>(countArg->ToNumber(vm)->Value());
count = countValue < DEFAULT_TAP_COUNT ? DEFAULT_TAP_COUNT : countValue;
}
Local<JSValueRef> distanceArg = runtimeCallInfo->GetCallArgRef(argNumber + 2);
if (!distanceArg.IsNull() && !distanceArg->IsUndefined()) {
auto distanceValue = static_cast<int32_t>(distanceArg->ToNumber(vm)->Value());
distanceThreshold = distanceValue < 0 ? DEFAULT_TAP_DISTANCE : distanceValue;
}
}
void CommonBridge::GetLongPressGestureValue(
@ -6838,8 +6844,10 @@ ArkUINativeModuleValue CommonBridge::AddTapGesture(ArkUIRuntimeCallInfo* runtime
GetGestureCommonValue(runtimeCallInfo, priority, mask);
int32_t fingers = DEFAULT_TAP_FINGER;
int32_t count = DEFAULT_TAP_COUNT;
GetTapGestureValue(runtimeCallInfo, fingers, count, NUM_4);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createTapGesture(count, fingers, nullptr);
double distanceThreshold = DEFAULT_TAP_DISTANCE;
GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_4);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, nullptr);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_6, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNode(nativeNode, gesture, priority, mask);
@ -6986,8 +6994,10 @@ ArkUINativeModuleValue CommonBridge::AddTapGestureToGroup(ArkUIRuntimeCallInfo*
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
int32_t fingers = DEFAULT_TAP_FINGER;
int32_t count = DEFAULT_TAP_COUNT;
GetTapGestureValue(runtimeCallInfo, fingers, count, NUM_1);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createTapGesture(count, fingers, nullptr);
double distanceThreshold = DEFAULT_TAP_DISTANCE;
GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_1);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, nullptr);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_3, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_4);

View File

@ -264,8 +264,8 @@ public:
static Local<panda::ObjectRef> CreateAreaObject(EcmaVM* vm, const RectF& rect, const OffsetF& origin);
static void GetGestureCommonValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& priority, int32_t& mask);
static void SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture);
static void GetTapGestureValue(
ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& count, uint32_t argNumber);
static void GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers,
int32_t& count, double& distanceThreshold, uint32_t argNumber);
static void GetLongPressGestureValue(
ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, bool& repeat, int32_t& duration, uint32_t argNumber);
static void GetPanGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers, int32_t& direction,

View File

@ -217,6 +217,7 @@ namespace OHOS::Ace::Framework {
namespace {
constexpr int32_t DEFAULT_TAP_FINGER = 1;
constexpr int32_t DEFAULT_TAP_COUNT = 1;
constexpr double DEFAULT_TAP_DISTANCE = std::numeric_limits<double>::infinity();
constexpr int32_t DEFAULT_LONG_PRESS_FINGER = 1;
constexpr int32_t DEFAULT_LONG_PRESS_DURATION = 500;
constexpr int32_t DEFAULT_PINCH_FINGER = 2;
@ -232,6 +233,7 @@ constexpr double DEFAULT_ROTATION_ANGLE = 1.0;
constexpr char GESTURE_FINGERS[] = "fingers";
constexpr char GESTURE_DISTANCE[] = "distance";
constexpr char TAP_GESTURE_DISTANCE[] = "distanceThreshold";
constexpr char GESTURE_SPEED[] = "speed";
constexpr char TAP_COUNT[] = "count";
constexpr char LONG_PRESS_REPEAT[] = "repeat";
@ -276,10 +278,12 @@ void JSTapGesture::Create(const JSCallbackInfo& args)
{
int32_t countNum = DEFAULT_TAP_COUNT;
int32_t fingersNum = DEFAULT_TAP_FINGER;
double distanceThresholdNum = DEFAULT_TAP_DISTANCE;
if (args.Length() > 0 && args[0]->IsObject()) {
JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
JSRef<JSVal> count = obj->GetProperty(TAP_COUNT);
JSRef<JSVal> fingers = obj->GetProperty(GESTURE_FINGERS);
JSRef<JSVal> distanceThreshold = obj->GetProperty(TAP_GESTURE_DISTANCE);
if (count->IsNumber()) {
int32_t countNumber = count->ToNumber<int32_t>();
@ -289,9 +293,14 @@ void JSTapGesture::Create(const JSCallbackInfo& args)
int32_t fingersNumber = fingers->ToNumber<int32_t>();
fingersNum = fingersNumber <= DEFAULT_TAP_FINGER ? DEFAULT_TAP_FINGER : fingersNumber;
}
if (distanceThreshold->IsNumber()) {
double distanceThresholdNumber = distanceThreshold->ToNumber<double>();
distanceThresholdNum = distanceThresholdNumber < 0? DEFAULT_TAP_DISTANCE : distanceThresholdNumber;
distanceThresholdNum = Dimension(distanceThresholdNum, DimensionUnit::VP).ConvertToPx();
}
}
TapGestureModel::GetInstance()->Create(countNum, fingersNum);
TapGestureModel::GetInstance()->Create(countNum, fingersNum, distanceThresholdNum);
}
void JSLongPressGesture::Create(const JSCallbackInfo& args)

View File

@ -215,7 +215,13 @@ void JSInteractableView::JsOnClick(const JSCallbackInfo& info)
#endif
};
ViewAbstractModel::GetInstance()->SetOnClick(std::move(onTap), std::move(onClick));
double distanceThreshold = std::numeric_limits<double>::infinity();
if (info.Length() > 1 && info[1]->IsNumber()) {
distanceThreshold = info[1]->ToNumber<double>();
}
distanceThreshold = Dimension(distanceThreshold, DimensionUnit::VP).ConvertToPx();
ViewAbstractModel::GetInstance()->SetOnClick(std::move(onTap), std::move(onClick), distanceThreshold);
CHECK_NULL_VOID(frameNode);
auto focusHub = frameNode->GetOrCreateFocusHub();
CHECK_NULL_VOID(focusHub);

View File

@ -9590,7 +9590,16 @@ void JSViewAbstract::JsOnClick(const JSCallbackInfo& info)
JSInteractableView::ReportClickEvent(node);
#endif
};
ViewAbstractModel::GetInstance()->SetOnClick(std::move(tmpOnTap), std::move(onClick));
double distanceThreshold = std::numeric_limits<double>::infinity();
if (info.Length() > 1 && info[1]->IsNumber()) {
distanceThreshold = info[1]->ToNumber<double>();
if (distanceThreshold < 0) {
distanceThreshold = std::numeric_limits<double>::infinity();
}
}
distanceThreshold = Dimension(distanceThreshold, DimensionUnit::VP).ConvertToPx();
ViewAbstractModel::GetInstance()->SetOnClick(std::move(tmpOnTap), std::move(onClick), distanceThreshold);
}
void JSViewAbstract::JsOnGestureJudgeBegin(const JSCallbackInfo& info)

View File

@ -65,11 +65,11 @@ void GestureModelImpl::Pop()
gestureProcessor->PopGesture();
}
void TapGestureModelImpl::Create(int32_t countNum, int32_t fingersNum)
void TapGestureModelImpl::Create(int32_t countNum, int32_t fingersNum, double distanceThreshold)
{
RefPtr<GestureProcessor> gestureProcessor;
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
auto gesture = AceType::MakeRefPtr<TapGesture>(countNum, fingersNum);
auto gesture = AceType::MakeRefPtr<TapGesture>(countNum, fingersNum, distanceThreshold);
gestureProcessor->PushGesture(gesture);
}

View File

@ -32,7 +32,7 @@ public:
class TapGestureModelImpl : public OHOS::Ace::TapGestureModel {
public:
void Create(int32_t countNum, int32_t fingersNum) override;
void Create(int32_t countNum, int32_t fingersNum, double distanceThreshold) override;
};
class LongPressGestureModelImpl : public OHOS::Ace::LongPressGestureModel {

View File

@ -1028,12 +1028,13 @@ void ViewAbstractModelImpl::SetHueRotate(float value)
frontDecoration->SetHueRotate(value);
}
void ViewAbstractModelImpl::SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc)
void ViewAbstractModelImpl::SetOnClick(
GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc, double distanceThreshold)
{
auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
CHECK_NULL_VOID(inspector);
auto impl = inspector->GetInspectorFunctionImpl();
RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>(1, 1);
RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>(1, 1, distanceThreshold);
tapGesture->SetOnActionId([func = std::move(tapEventFunc), impl](GestureEvent& info) {
if (impl) {
impl->UpdateEventInfo(info);

View File

@ -177,7 +177,8 @@ public:
void SetFreeze(bool) override {}
void SetClickEffectLevel(const ClickEffectLevel& level, float scaleValue) override {}
void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc) override;
void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc,
double distanceThreshold) override;
void SetOnGestureJudgeBegin(NG::GestureJudgeFunc&& gestureJudgeFunc) override {}
void SetOnTouchIntercept(NG::TouchInterceptFunc&& touchInterceptFunc) override {}
void SetShouldBuiltInRecognizerParallelWith(

View File

@ -1020,13 +1020,13 @@ void ViewAbstract::DisableOnAreaChange(FrameNode* frameNode)
frameNode->ClearUserOnAreaChange();
}
void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc)
void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc, double distanceThreshold)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
CHECK_NULL_VOID(frameNode);
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
CHECK_NULL_VOID(gestureHub);
gestureHub->SetUserOnClick(std::move(clickEventFunc));
gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
auto focusHub = frameNode->GetOrCreateFocusHub();
CHECK_NULL_VOID(focusHub);
@ -3749,11 +3749,11 @@ void ViewAbstract::SetOnBlur(FrameNode* frameNode, OnBlurFunc&& onBlurCallback)
focusHub->SetOnBlurCallback(std::move(onBlurCallback));
}
void ViewAbstract::SetOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc)
void ViewAbstract::SetOnClick(FrameNode* frameNode, GestureEventFunc&& clickEventFunc, double distanceThreshold)
{
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
CHECK_NULL_VOID(gestureHub);
gestureHub->SetUserOnClick(std::move(clickEventFunc));
gestureHub->SetUserOnClick(std::move(clickEventFunc), distanceThreshold);
auto focusHub = frameNode->GetFocusHub();
CHECK_NULL_VOID(focusHub);

View File

@ -260,7 +260,8 @@ public:
static void SetTransformMatrix(const Matrix4 &matrix);
// event
static void SetOnClick(GestureEventFunc &&clickEventFunc);
static void SetOnClick(GestureEventFunc &&clickEventFunc,
double distanceThreshold = std::numeric_limits<double>::infinity());
static void SetOnGestureJudgeBegin(GestureJudgeFunc &&gestureJudgeFunc);
static void SetOnTouchIntercept(TouchInterceptFunc &&touchInterceptFunc);
static void SetShouldBuiltInRecognizerParallelWith(
@ -610,7 +611,8 @@ public:
const OffsetF &oldOrigin, const RectF &rect, const OffsetF &origin)> &&onAreaChanged);
static void SetOnFocus(FrameNode* frameNode, OnFocusFunc &&onFocusCallback);
static void SetOnBlur(FrameNode* frameNode, OnBlurFunc &&onBlurCallback);
static void SetOnClick(FrameNode* frameNode, GestureEventFunc &&clickEventFunc);
static void SetOnClick(FrameNode* frameNode, GestureEventFunc &&clickEventFunc,
double distanceThreshold = std::numeric_limits<double>::infinity());
static void SetOnTouch(FrameNode* frameNode, TouchEventFunc &&touchEventFunc);
static void SetOnDragStart(FrameNode* frameNode,
std::function<DragDropInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>&& onDragStart);

View File

@ -251,7 +251,8 @@ public:
virtual void SetFreeze(bool freeze) = 0;
// event
virtual void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc) = 0;
virtual void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc,
double distanceThreshold = std::numeric_limits<double>::infinity()) = 0;
virtual void SetOnGestureJudgeBegin(NG::GestureJudgeFunc&& gestureJudgeFunc) = 0;
virtual void SetOnTouchIntercept(NG::TouchInterceptFunc&& touchInterceptFunc) = 0;
virtual void SetShouldBuiltInRecognizerParallelWith(

View File

@ -888,9 +888,9 @@ public:
ViewAbstract::SetClickEffectLevel(level, scaleValue);
}
void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc) override
void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc, double distanceThreshold) override
{
ViewAbstract::SetOnClick(std::move(tapEventFunc));
ViewAbstract::SetOnClick(std::move(tapEventFunc), distanceThreshold);
}
void SetOnGestureJudgeBegin(NG::GestureJudgeFunc&& gestureJudgeFunc) override

View File

@ -1247,15 +1247,19 @@ void GestureEventHub::CheckClickActuator()
}
}
void GestureEventHub::SetUserOnClick(GestureEventFunc&& clickEvent)
void GestureEventHub::SetUserOnClick(GestureEventFunc&& clickEvent, double distanceThreshold)
{
CheckClickActuator();
if (parallelCombineClick) {
userParallelClickEventActuator_->SetUserCallback(std::move(clickEvent));
SetFocusClickEvent(userParallelClickEventActuator_->GetClickEvent());
auto clickRecognizer = userParallelClickEventActuator_->GetClickRecognizer();
clickRecognizer->SetDistanceThreshold(distanceThreshold);
} else {
clickEventActuator_->SetUserCallback(std::move(clickEvent));
SetFocusClickEvent(clickEventActuator_->GetClickEvent());
auto clickRecognizer = clickEventActuator_->GetClickRecognizer();
clickRecognizer->SetDistanceThreshold(distanceThreshold);
}
}

View File

@ -282,7 +282,8 @@ public:
void CheckClickActuator();
// Set by user define, which will replace old one.
void SetUserOnClick(GestureEventFunc&& clickEvent);
void SetUserOnClick(GestureEventFunc&& clickEvent,
double distanceThreshold = std::numeric_limits<double>::infinity());
// Set by JS FrameNode.
void SetJSFrameNodeOnClick(GestureEventFunc&& clickEvent);

View File

@ -51,6 +51,17 @@ void ClickRecognizer::ForceCleanRecognizer()
bool ClickRecognizer::IsPointInRegion(const TouchEvent& event)
{
if (distanceThreshold_ < std::numeric_limits<double>::infinity()) {
Offset offset = event.GetScreenOffset() - touchPoints_[event.id].GetScreenOffset();
if (offset.GetDistance() > distanceThreshold_) {
TAG_LOGI(AceLogTag::ACE_GESTURE, "Click move distance is larger than distanceThreshold_, "
"distanceThreshold_ is %{public}f", distanceThreshold_);
Adjudicate(AceType::Claim(this), GestureDisposal::REJECT);
return false;
} else {
return true;
}
}
PointF localPoint(event.x, event.y);
auto frameNode = GetAttachedNode();
if (!frameNode.Invalid()) {
@ -72,11 +83,15 @@ bool ClickRecognizer::IsPointInRegion(const TouchEvent& event)
return true;
}
ClickRecognizer::ClickRecognizer(int32_t fingers, int32_t count) : MultiFingersRecognizer(fingers), count_(count)
ClickRecognizer::ClickRecognizer(int32_t fingers, int32_t count, double distanceThreshold)
: MultiFingersRecognizer(fingers), count_(count), distanceThreshold_(distanceThreshold)
{
if (fingers_ > MAX_TAP_FINGERS || fingers_ < DEFAULT_TAP_FINGERS) {
fingers_ = DEFAULT_TAP_FINGERS;
}
if (distanceThreshold_ < 0) {
distanceThreshold_ = std::numeric_limits<double>::infinity();
}
}
void ClickRecognizer::InitGlobalValue(SourceType sourceType)
@ -504,7 +519,8 @@ bool ClickRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognize
return false;
}
if (curr->count_ != count_ || curr->fingers_ != fingers_ || curr->priorityMask_ != priorityMask_) {
if (curr->count_ != count_ || curr->fingers_ != fingers_ || curr->priorityMask_ != priorityMask_ ||
curr->distanceThreshold_ != distanceThreshold_) {
ResetStatus();
return false;
}
@ -525,7 +541,7 @@ RefPtr<GestureSnapshot> ClickRecognizer::Dump() const
RefPtr<Gesture> ClickRecognizer::CreateGestureFromRecognizer() const
{
return AceType::MakeRefPtr<TapGesture>(count_, fingers_);
return AceType::MakeRefPtr<TapGesture>(count_, fingers_, distanceThreshold_);
}
void ClickRecognizer::CleanRecognizerState()

View File

@ -34,7 +34,7 @@ class ClickRecognizer : public MultiFingersRecognizer {
public:
ClickRecognizer() = default;
ClickRecognizer(int32_t fingers, int32_t count);
ClickRecognizer(int32_t fingers, int32_t count, double distanceThreshold = std::numeric_limits<double>::infinity());
~ClickRecognizer() override = default;
@ -61,6 +61,14 @@ public:
onAccessibilityEventFunc_ = std::move(onAccessibilityEvent);
}
void SetDistanceThreshold(double distanceThreshold)
{
distanceThreshold_ = distanceThreshold;
if (distanceThreshold_ < 0) {
distanceThreshold_ = std::numeric_limits<double>::infinity();
}
}
int GetCount()
{
return count_;
@ -118,6 +126,7 @@ private:
bool CheckNeedReceiveEvent();
int32_t count_ = 1;
double distanceThreshold_ = std::numeric_limits<double>::infinity();
// number of tap action.
int32_t tappedCount_ = 0;

View File

@ -21,7 +21,7 @@ namespace OHOS::Ace::NG {
RefPtr<NGGestureRecognizer> TapGesture::CreateRecognizer()
{
auto clickRecognizer = AceType::MakeRefPtr<ClickRecognizer>(fingers_, count_);
auto clickRecognizer = AceType::MakeRefPtr<ClickRecognizer>(fingers_, count_, distanceThreshold_);
if (onActionId_) {
clickRecognizer->SetOnAction(*onActionId_);
}

View File

@ -42,7 +42,8 @@ public:
gestureInfo_ = MakeRefPtr<GestureInfo>(GestureTypeName::TAP_GESTURE, GestureTypeName::TAP_GESTURE, false);
}
}
TapGesture(int32_t count, int32_t fingers) : Gesture(fingers), count_(count)
TapGesture(int32_t count, int32_t fingers, double distanceThreshold = std::numeric_limits<double>::infinity())
: Gesture(fingers), count_(count), distanceThreshold_(distanceThreshold)
{
if (gestureInfo_) {
gestureInfo_->SetType(GestureTypeName::TAP_GESTURE);
@ -63,6 +64,7 @@ protected:
private:
int32_t count_ = 1;
double distanceThreshold_ = std::numeric_limits<double>::infinity();
};
} // namespace OHOS::Ace::NG

View File

@ -47,7 +47,7 @@ public:
static TapGestureModel* GetInstance();
virtual ~TapGestureModel() = default;
virtual void Create(int32_t countNum, int32_t fingersNum) = 0;
virtual void Create(int32_t countNum, int32_t fingersNum, double distanceThreshold) = 0;
private:
static std::unique_ptr<TapGestureModel> instance_;

View File

@ -93,11 +93,11 @@ void GestureModelNG::SetTag(const std::string& tag)
gesture->SetTag(tag);
}
void TapGestureModelNG::Create(int32_t countNum, int32_t fingersNum)
void TapGestureModelNG::Create(int32_t countNum, int32_t fingersNum, double distanceThreshold)
{
RefPtr<GestureProcessor> gestureProcessor;
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
auto gesture = AceType::MakeRefPtr<NG::TapGesture>(countNum, fingersNum);
auto gesture = AceType::MakeRefPtr<NG::TapGesture>(countNum, fingersNum, distanceThreshold);
gestureProcessor->PushGestureNG(gesture);
}

View File

@ -32,7 +32,8 @@ public:
class ACE_EXPORT TapGestureModelNG : public OHOS::Ace::TapGestureModel {
public:
void Create(int32_t countNum, int32_t fingersNum) override;
void Create(int32_t countNum, int32_t fingersNum,
double distanceThreshold = std::numeric_limits<double>::infinity()) override;
};
class ACE_EXPORT LongPressGestureModelNG : public OHOS::Ace::LongPressGestureModel {

View File

@ -30,10 +30,12 @@ class ClickRecognizer : public MultiFingersRecognizer {
public:
ClickRecognizer() = default;
ClickRecognizer(const WeakPtr<PipelineBase>& context, int32_t fingers, int32_t count)
ClickRecognizer(const WeakPtr<PipelineBase>& context, int32_t fingers,
int32_t count, double distanceThreshold = std::numeric_limits<double>::infinity())
: count_(count), context_(context)
{
fingers_ = fingers;
distanceThreshold_ = distanceThreshold;
}
explicit ClickRecognizer(const WeakPtr<PipelineBase>& context) : context_(context) {}
~ClickRecognizer() override = default;
@ -71,6 +73,7 @@ private:
void InitGlobalValue(SourceType deviceId);
int32_t count_ = 1;
double distanceThreshold_ = std::numeric_limits<double>::infinity();
// number of fingers which put on the screen
int32_t pointsCount_ = 0;
int32_t tappedCount_ = 0;

View File

@ -21,7 +21,8 @@ namespace OHOS::Ace {
RefPtr<GestureRecognizer> TapGesture::CreateRecognizer(WeakPtr<PipelineBase> context)
{
auto clickRecognizer = AceType::MakeRefPtr<OHOS::Ace::ClickRecognizer>(context, fingers_, count_);
auto clickRecognizer = AceType::MakeRefPtr<OHOS::Ace::ClickRecognizer>(
context, fingers_, count_, distanceThreshold_);
if (onActionId_) {
clickRecognizer->SetOnAction(*onActionId_);
}

View File

@ -32,7 +32,8 @@ class ACE_EXPORT TapGesture : public Gesture {
public:
TapGesture() = default;
TapGesture(int32_t count, int32_t fingers) : Gesture(fingers), count_(count) {}
TapGesture(int32_t count, int32_t fingers, double distanceThreshold = std::numeric_limits<double>::infinity())
: Gesture(fingers), count_(count), distanceThreshold_(distanceThreshold) {}
~TapGesture() override = default;
protected:
@ -40,6 +41,7 @@ protected:
private:
int32_t count_ = 1;
double distanceThreshold_ = std::numeric_limits<double>::infinity();
};
} // namespace OHOS::Ace

View File

@ -2697,6 +2697,8 @@ struct ArkUIGestureInterruptInfo {
struct ArkUIGestureModifier {
ArkUIGesture* (*createTapGesture)(ArkUI_Int32 count, ArkUI_Int32 fingers, void* userData);
ArkUIGesture* (*createTapGestureWithDistanceThreshold)(
ArkUI_Int32 count, ArkUI_Int32 fingers, ArkUI_Float64 distanceThreshold, void* userData);
ArkUIGesture* (*createLongPressGesture)(ArkUI_Int32 fingers, bool repeat, ArkUI_Int32 duration, void* userData);
ArkUIGesture* (*createPanGesture)(
ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI_Float64 distance, void* userData);

View File

@ -73,7 +73,17 @@ ArkUIGesture* createPanGesture(ArkUI_Int32 fingers, ArkUI_Int32 direction, ArkUI
ArkUIGesture* createTapGesture(ArkUI_Int32 count, ArkUI_Int32 fingers, void* userData)
{
auto tapGestureObject = AceType::MakeRefPtr<TapGesture>(count, fingers);
auto tapGestureObject = AceType::MakeRefPtr<TapGesture>(count, fingers, std::numeric_limits<double>::infinity());
tapGestureObject->SetUserData(userData);
tapGestureObject->IncRefCount();
return reinterpret_cast<ArkUIGesture*>(AceType::RawPtr(tapGestureObject));
}
ArkUIGesture* createTapGestureWithDistanceThreshold(
ArkUI_Int32 count, ArkUI_Int32 fingers, double distanceThreshold, void* userData)
{
distanceThreshold = Dimension(distanceThreshold, DimensionUnit::VP).ConvertToPx();
auto tapGestureObject = AceType::MakeRefPtr<TapGesture>(count, fingers, distanceThreshold);
tapGestureObject->SetUserData(userData);
tapGestureObject->IncRefCount();
return reinterpret_cast<ArkUIGesture*>(AceType::RawPtr(tapGestureObject));
@ -429,6 +439,7 @@ const ArkUIGestureModifier* GetGestureModifier()
{
static const ArkUIGestureModifier modifier = {
createTapGesture,
createTapGestureWithDistanceThreshold,
createLongPressGesture,
createPanGesture,
createPinchGesture,

View File

@ -618,6 +618,32 @@ typedef struct {
* @return Returns the gesture type.
*/
ArkUI_GestureRecognizerType (*getGestureType)(ArkUI_GestureRecognizer* recognizer);
/**
* @brief Creates a tap gesture that is subject to distance restrictions.
*
* 1. This API is used to trigger a tap gesture with one, two, or more taps. \n
* 2. If multi-tap is configured, the timeout interval between a lift and the next tap is 300 ms. \n
* 3. If the distance between the last tapped position and the current tapped position exceeds 60 vp,
* gesture recognition fails. \n
* 4. If the value is greater than 1, the tap gesture will fail to be recognized when the number of fingers
* touching the screen within 300 ms of the first finger touch is less than the required number,
* or when the number of fingers lifted from the screen within 300 ms of the first finger's being lifted
* is less than the required number. \n
* 5. When the number of fingers touching the screen exceeds the set value, the gesture can be recognized. \n
* 6. If the finger moves beyond the preset distance limit, gesture recognition fails. \n
*
* @param countNum Indicates the number of consecutive taps. If the value is less than 1 or is not set, the default
* value <b>1</b> is used.
* @param fingersNum Indicates the number of fingers required to trigger a tap. The value ranges from 1 to 10.
* If the value is less than 1 or is not set, the default value <b>1</b> is used.
* @param distanceThreshold Indicates the allowed moving distance of a finger.
* The unit of this parameter is px.
* If the value is less than 0, it will be converted to the default value of infinity.
* @return Returns the pointer to the created gesture.
*/
ArkUI_GestureRecognizer* (*createTapGestureWithDistanceThreshold)(
int32_t countNum, int32_t fingersNum, double distanceThreshold);
} ArkUI_NativeGestureAPI_1;
#ifdef __cplusplus

View File

@ -212,6 +212,17 @@ ArkUI_GestureRecognizer* CreateTapGesture(int32_t count, int32_t fingers)
return ndkGesture;
}
ArkUI_GestureRecognizer* CreateTapGestureWithDistanceThreshold(int32_t count, int32_t fingers, double distanceThreshold)
{
count = std::max(count, DEFAULT_TAP_COUNT);
fingers = std::clamp(fingers, DEFAULT_TAP_FINGERS, MAX_TAP_FINGERS);
auto* ndkGesture = new ArkUI_GestureRecognizer{ TAP_GESTURE, nullptr, nullptr, nullptr };
auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->
createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, ndkGesture);
ndkGesture->gesture = gesture;
return ndkGesture;
}
ArkUI_GestureRecognizer* CreateLongPressGesture(int32_t fingers, bool repeatResult, int32_t duration)
{
auto* ndkGesture = new ArkUI_GestureRecognizer{ LONG_PRESS_GESTURE, nullptr, nullptr, nullptr };

View File

@ -25,6 +25,9 @@ namespace OHOS::Ace::GestureModel {
ArkUI_GestureRecognizer* CreateTapGesture(int32_t count, int32_t fingers);
ArkUI_GestureRecognizer* CreateTapGestureWithDistanceThreshold(
int32_t count, int32_t fingers, double distanceThreshold);
ArkUI_GestureRecognizer* CreateLongPressGesture(int32_t fingers, bool repeatResult, int32_t duration);
ArkUI_GestureRecognizer* CreatePanGesture(int32_t fingersNum, ArkUI_GestureDirectionMask mask, double distanceNum);

View File

@ -131,6 +131,7 @@ ArkUI_NativeGestureAPI_1 gestureImpl_1 = {
OHOS::Ace::GestureModel::RemoveGestureFromNode,
OHOS::Ace::GestureModel::SetGestureInterrupterToNode,
OHOS::Ace::GestureModel::GetGestureType,
OHOS::Ace::GestureModel::CreateTapGestureWithDistanceThreshold,
};
ArkUI_NativeAnimateAPI_1 animateImpl_1 = {