diff --git a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp index 100e85a6e8277a20407db80b0ecfbca87d112640..899b53b2ee8dfe2866588f7e57f8955bce2676b8 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp @@ -479,7 +479,7 @@ void JSPanGesture::Create(const JSCallbackInfo& args) void JSSwipeGesture::Create(const JSCallbackInfo& args) { int32_t fingersNum = DEFAULT_SLIDE_FINGER; - double speedNum = DEFAULT_SLIDE_SPEED; + Dimension speedNum = Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::VP); SwipeDirection slideDirection; bool isLimitFingerCount = false; @@ -500,7 +500,9 @@ void JSSwipeGesture::Create(const JSCallbackInfo& args) } if (speed->IsNumber()) { double speedNumber = speed->ToNumber(); - speedNum = LessOrEqual(speedNumber, 0.0) ? DEFAULT_SLIDE_SPEED : speedNumber; + speedNum = LessOrEqual(speedNumber, 0.0) ? + Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::VP) : + Dimension(speedNumber, DimensionUnit::VP); } if (directionNum->IsNumber()) { uint32_t directNum = directionNum->ToNumber(); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.cpp index d5f0fcbf4557fb5cfd1085457c9a5ae57bec33fc..5101d8c7509074b67421bdeb39da5620a381216c 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.cpp @@ -112,7 +112,7 @@ void PanGestureModelImpl::SetPanGestureOption(const RefPtr& pa } void SwipeGestureModelImpl::Create( - int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum, bool isLimitFingerCount) + int32_t fingersNum, const SwipeDirection& slideDirection, const Dimension& speedNum, bool isLimitFingerCount) { RefPtr gestureProcessor; gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent(); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h index d791838a2982123d0fe5eb406a3e95f4a6b9ae48..13fc0500729ff432102bd06f99ff9b5c31584f04 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h @@ -52,8 +52,8 @@ public: class SwipeGestureModelImpl : public OHOS::Ace::SwipeGestureModel { public: - void Create( - int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum, bool isLimitFingerCount) override; + void Create(int32_t fingersNum, const SwipeDirection& slideDirection, + const Dimension& speedNum, bool isLimitFingerCount) override; }; class PinchGestureModelImpl : public OHOS::Ace::PinchGestureModel { diff --git a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp index 4abedc5e5b3a804aa58eff2b924217fd7e7f1dab..734564efd392a6460df4669459c3b6f0fdb5528c 100644 --- a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp @@ -180,10 +180,11 @@ void SwipeRecognizer::HandleTouchUpEvent(const TouchEvent& event) std::chrono::duration duration = event.time - touchDownTime_; auto seconds = duration.count(); resultSpeed_ = LessOrEqual(seconds, 0.0) ? 0.0 : offset.GetDistance() / seconds; - if (resultSpeed_ < speed_) { + auto speed = speed_.ConvertToPx(); + if (resultSpeed_ < speed) { if (currentFingers_ - 1 + static_cast(matchedTouch_.size()) < fingers_) { TAG_LOGI(AceLogTag::ACE_GESTURE, "The result speed %{public}f is less than duration %{public}f", - resultSpeed_, speed_); + resultSpeed_, speed); Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); } } else { @@ -239,7 +240,8 @@ void SwipeRecognizer::HandleTouchUpEvent(const AxisEvent& event) resultSpeed_ = LessOrEqual(duration_ms.count(), 0.0) ? 0.0 : axisOffset_.GetDistance() / duration_ms.count() * RATIO_MS_TO_S; - if (resultSpeed_ < speed_) { + auto speed = speed_.ConvertToPx(); + if (resultSpeed_ < speed) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); } else { auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); @@ -457,7 +459,7 @@ void SwipeRecognizer::HandleReports(const GestureEvent& info, GestureCallbackTyp swipeReport.SetId(frameNode->GetId()); swipeReport.SetSwipeDirection(static_cast(direction_.type)); swipeReport.SetTouchEvents(downEvents_); - swipeReport.SetSpeed(speed_); + swipeReport.SetSpeed(speed_.ConvertToPx()); swipeReport.SetActualSpeed(resultSpeed_); swipeReport.SetFingerList(info.GetFingerList()); Reporter::GetInstance().HandleUISessionReporting(swipeReport); @@ -531,7 +533,8 @@ bool SwipeRecognizer::ReconcileFrom(const RefPtr& recognize return false; } - if (curr->fingers_ != fingers_ || (curr->direction_.type != direction_.type) || !NearZero(curr->speed_ - speed_) || + if (curr->fingers_ != fingers_ || (curr->direction_.type != direction_.type) || + !NearZero((curr->speed_).ConvertToPx() - speed_.ConvertToPx()) || priorityMask_ != curr->priorityMask_) { ResetStatus(); return false; @@ -548,7 +551,7 @@ RefPtr SwipeRecognizer::Dump() const RefPtr info = NGGestureRecognizer::Dump(); std::stringstream oss; oss << "direction: " << direction_.type << ", " - << "speed: " << speed_ << ", " + << "speed: " << speed_.ConvertToPx() << ", " << "fingers: " << fingers_ << ", " << DumpGestureInfo(); info->customInfo = oss.str(); diff --git a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h index 900db51525964dd9cdb67e2e5e1bbc31c7b5aa8d..a6b4ecd8a2bf2a42839a027267d56ef4700b9576 100644 --- a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h @@ -31,9 +31,14 @@ class SwipeRecognizer : public MultiFingersRecognizer { DECLARE_ACE_TYPE(SwipeRecognizer, MultiFingersRecognizer); public: - SwipeRecognizer(int32_t fingers, const SwipeDirection& direction, double speed, bool isLimitFingerCount = false) + SwipeRecognizer(int32_t fingers, const SwipeDirection& direction, const Dimension& speed, + bool isLimitFingerCount = false) : MultiFingersRecognizer(fingers, isLimitFingerCount), direction_(direction), speed_(speed) {} + SwipeRecognizer(int32_t fingers, const SwipeDirection& direction, double speed, bool isLimitFingerCount = false) + : MultiFingersRecognizer(fingers, isLimitFingerCount), + direction_(direction), speed_(Dimension(speed, DimensionUnit::VP)) + {} ~SwipeRecognizer() override = default; void OnAccepted() override; @@ -61,6 +66,11 @@ public: } void SetSpeed(double speed) + { + speed_ = Dimension(speed, DimensionUnit::VP); + } + + void SetSpeed(const Dimension& speed) { speed_ = speed; } @@ -72,7 +82,7 @@ public: double GetSpeed() const { - return speed_; + return speed_.ConvertToPx(); } private: @@ -96,7 +106,7 @@ private: bool CheckAngle(double angle); SwipeDirection direction_; - double speed_ = 0.0; + Dimension speed_ = Dimension(0.0, DimensionUnit::VP); TouchEvent lastTouchEvent_; std::map downEvents_; diff --git a/frameworks/core/components_ng/gestures/swipe_gesture.cpp b/frameworks/core/components_ng/gestures/swipe_gesture.cpp index 75b44814a7ed9edbcd3925f7e51eac7ae8481984..f7dc8ed15ae285b34ef94a3d855b0d63e5ac2c77 100644 --- a/frameworks/core/components_ng/gestures/swipe_gesture.cpp +++ b/frameworks/core/components_ng/gestures/swipe_gesture.cpp @@ -25,9 +25,8 @@ RefPtr SwipeGesture::CreateRecognizer() auto context = PipelineContext::GetCurrentContextSafely(); CHECK_NULL_RETURN(context, nullptr); - double speed = context->NormalizeToPx(Dimension(speed_, DimensionUnit::VP)); RefPtr swipeRecognizer; - swipeRecognizer = AceType::MakeRefPtr(fingers_, direction_, speed, isLimitFingerCount_); + swipeRecognizer = AceType::MakeRefPtr(fingers_, direction_, speed_, isLimitFingerCount_); if (onActionId_) { swipeRecognizer->SetOnAction(*onActionId_); } diff --git a/frameworks/core/components_ng/gestures/swipe_gesture.h b/frameworks/core/components_ng/gestures/swipe_gesture.h index 3840c522d27dae0fdf1d22ed7f2f45699e9e7e1d..871f946d4a71ab30120ef20be643c1f4ee3576c2 100644 --- a/frameworks/core/components_ng/gestures/swipe_gesture.h +++ b/frameworks/core/components_ng/gestures/swipe_gesture.h @@ -28,6 +28,22 @@ class ACE_FORCE_EXPORT SwipeGesture : public Gesture { public: SwipeGesture(int32_t fingers, const SwipeDirection& direction, double speed, bool limitFingerCount = false) + { + fingers_ = fingers; + direction_ = direction; + speed_ = Dimension(speed, DimensionUnit::VP); + isLimitFingerCount_ = limitFingerCount; + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::SWIPE_GESTURE); + gestureInfo_->SetRecognizerType(GestureTypeName::SWIPE_GESTURE); + } else { + gestureInfo_ = + MakeRefPtr(GestureTypeName::SWIPE_GESTURE, GestureTypeName::SWIPE_GESTURE, false); + } + }; + + SwipeGesture( + int32_t fingers, const SwipeDirection& direction, const Dimension& speed, bool limitFingerCount = false) { fingers_ = fingers; direction_ = direction; @@ -47,7 +63,7 @@ public: #ifdef ARKUI_CAPI_UNITTEST double GetSpeed() { - return speed_; + return speed_.ConvertToPx(); } SwipeDirection GetDirection() @@ -60,7 +76,7 @@ protected: private: SwipeDirection direction_; - double speed_ = 0.0; + Dimension speed_ = Dimension(0.0, DimensionUnit::VP); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/gesture/gesture_model.h b/frameworks/core/components_ng/pattern/gesture/gesture_model.h index c5724c5665ffc1f30e2aea12244febd49b240d84..c32e9d9f67855f6f677771ae5b3f9c6de9ca94d5 100644 --- a/frameworks/core/components_ng/pattern/gesture/gesture_model.h +++ b/frameworks/core/components_ng/pattern/gesture/gesture_model.h @@ -88,8 +88,8 @@ public: static SwipeGestureModel* GetInstance(); virtual ~SwipeGestureModel() = default; - virtual void Create( - int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum, bool isLimitFingerCount) = 0; + virtual void Create(int32_t fingersNum, const SwipeDirection& slideDirection, + const Dimension& speedNum, bool isLimitFingerCount) = 0; private: static std::unique_ptr instance_; diff --git a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp index c6734e879d91721fbc14e179a48acb277c8e3033..ad31a9a030bd64d52c11ff2dc7fa53d13fb29396 100644 --- a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp @@ -171,7 +171,7 @@ void PanGestureModelNG::SetPanGestureOption(const RefPtr& panG } void SwipeGestureModelNG::Create( - int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum, bool isLimitFingerCount) + int32_t fingersNum, const SwipeDirection& slideDirection, const Dimension& speedNum, bool isLimitFingerCount) { RefPtr gestureProcessor; gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor(); diff --git a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h index 0864483d6cbf7a1f9698854f883a64245fa3d812..7328e7db0da3354434c7860f854f5fcdc6f0d376 100644 --- a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h +++ b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h @@ -54,7 +54,7 @@ public: class ACE_EXPORT SwipeGestureModelNG : public OHOS::Ace::SwipeGestureModel { public: - void Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum, + void Create(int32_t fingersNum, const SwipeDirection& slideDirection, const Dimension& speedNum, bool isLimitFingerCount = false) override; }; diff --git a/frameworks/core/gestures/slide_gesture.h b/frameworks/core/gestures/slide_gesture.h index ba51094ee1526c3bd52ecfe955d215a84700c4bc..f2f2e667de328ce60ab054594811dc1a7c91f90a 100644 --- a/frameworks/core/gestures/slide_gesture.h +++ b/frameworks/core/gestures/slide_gesture.h @@ -27,6 +27,13 @@ class ACE_EXPORT SwipeGesture : public Gesture { DECLARE_ACE_TYPE(SwipeGesture, Gesture); public: + SwipeGesture(int32_t fingers, const SwipeDirection& direction, const Dimension& speed) + { + fingers_ = fingers; + direction_ = direction; + speed_ = speed.ConvertToVp(); + }; + SwipeGesture(int32_t fingers, const SwipeDirection& direction, double speed) { fingers_ = fingers; diff --git a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp index 5efe35d1c76ca478ef081509eed214c1477a75b2..a5276cb935605992c02c8ab15ecc899d7d312320 100644 --- a/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_gesture_modifier.cpp @@ -144,7 +144,9 @@ ArkUIGesture* createSwipeGesture( if (static_cast(directions) & ArkUI_GESTURE_DIRECTION_VERTICAL) { swipeDirection.type += SwipeDirection::VERTICAL; } - auto swipeGestureObject = AceType::MakeRefPtr(fingers, swipeDirection, speed, limitFingerCount); + auto speedDimension = Dimension(speed, DimensionUnit::PX); + auto swipeGestureObject = AceType::MakeRefPtr( + fingers, swipeDirection, speedDimension, limitFingerCount); swipeGestureObject->SetUserData(userData); swipeGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(swipeGestureObject)); @@ -171,7 +173,9 @@ ArkUIGesture* createSwipeGestureByModifier( swipeDirection.type = SwipeDirection::NONE; break; } - auto swipeGestureObject = AceType::MakeRefPtr(fingers, swipeDirection, speed, limitFingerCount); + auto speedDimension = Dimension(speed, DimensionUnit::VP); + auto swipeGestureObject = AceType::MakeRefPtr( + fingers, swipeDirection, speedDimension, limitFingerCount); swipeGestureObject->IncRefCount(); return reinterpret_cast(AceType::RawPtr(swipeGestureObject)); } diff --git a/interfaces/native/node/gesture_impl.cpp b/interfaces/native/node/gesture_impl.cpp index 1aa058241ed7a80374d38611689f0851c3bf9308..6016efbef24e307e075a4052a0989d5ac533295f 100644 --- a/interfaces/native/node/gesture_impl.cpp +++ b/interfaces/native/node/gesture_impl.cpp @@ -771,12 +771,10 @@ ArkUI_GestureRecognizer* CreateSwipeGesture(int32_t fingers, ArkUI_GestureDirect 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* ndkGesture = new ArkUI_GestureRecognizer{ SWIPE_GESTURE, nullptr, nullptr, nullptr }; auto* gesture = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers()->getGestureModifier()->createSwipeGesture(fingers, - directions, speedNum, false, ndkGesture); + directions, speed, false, ndkGesture); ndkGesture->gesture = gesture; return ndkGesture; } diff --git a/test/unittest/core/gestures/swipe_recognizer_test_ng.cpp b/test/unittest/core/gestures/swipe_recognizer_test_ng.cpp index dbf25bcf1e07d0cdf538b3364a3287abf26c64fd..6a153940f67a7f7d01817d9735e19b102b69e6c9 100644 --- a/test/unittest/core/gestures/swipe_recognizer_test_ng.cpp +++ b/test/unittest/core/gestures/swipe_recognizer_test_ng.cpp @@ -689,7 +689,7 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeRecognizerTest007, TestSize.Level1) */ swipeRecognizer->fingers_ = swipeRecognizerPtr->fingers_; swipeRecognizer->direction_.type = swipeRecognizerPtr->direction_.type; - swipeRecognizer->speed_ = 1; + swipeRecognizer->speed_ = Dimension(1, DimensionUnit::PX); result = swipeRecognizer->ReconcileFrom(swipeRecognizerPtr); EXPECT_EQ(result, false); } @@ -855,21 +855,21 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureTest001, TestSize.Level1) double speedNum = DEFAULT_SLIDE_SPEED; SwipeDirection slideDirection; SwipeGestureModelNG swipeGestureModelNG; - swipeGestureModelNG.Create(fingersNum, slideDirection, speedNum); + swipeGestureModelNG.Create(fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX)); RefPtr gestureProcessor; gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor(); auto swipeGestureNG = AceType::DynamicCast(gestureProcessor->TopGestureNG()); - SwipeGesture swipeGesture = SwipeGesture(fingersNum, slideDirection, speedNum); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + SwipeGesture swipeGesture = SwipeGesture(fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX)); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); /** * @tc.steps: step2. call CreateRecognizer function and compare result * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed */ auto swipeRecognizer = AceType::DynamicCast(swipeGesture.CreateRecognizer()); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); /** * @tc.steps: step2. call CreateRecognizer function and compare result @@ -882,7 +882,7 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureTest001, TestSize.Level1) swipeGesture.onActionEndId_ = std::move(onActionEndId); swipeGesture.onActionCancelId_ = std::move(onActionCancelId); swipeRecognizer = AceType::DynamicCast(swipeGesture.CreateRecognizer()); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); } /** @@ -898,21 +898,21 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureCreateRecognizerTest001, TestSize.Le double speedNum = DEFAULT_SLIDE_SPEED; SwipeDirection slideDirection; SwipeGestureModelNG swipeGestureModelNG; - swipeGestureModelNG.Create(fingersNum, slideDirection, speedNum); + swipeGestureModelNG.Create(fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX)); RefPtr gestureProcessor; gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor(); auto swipeGestureNG = AceType::DynamicCast(gestureProcessor->TopGestureNG()); - SwipeGesture swipeGesture = SwipeGesture(fingersNum, slideDirection, speedNum); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + SwipeGesture swipeGesture = SwipeGesture(fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX)); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); /** * @tc.steps: step2. call CreateRecognizer function and compare result * @tc.steps: case1: onActionId, onActionEndId, onActionCancelId not existed */ auto swipeRecognizer = AceType::DynamicCast(swipeGesture.CreateRecognizer()); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); /** * @tc.steps: step2. call CreateRecognizer function and compare result @@ -927,7 +927,7 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureCreateRecognizerTest001, TestSize.Le auto onActionStart = [](GestureEvent& info) { return true; }; swipeGesture.SetOnActionId(onActionStart); swipeRecognizer = AceType::DynamicCast(swipeGesture.CreateRecognizer()); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); } /** @@ -1199,7 +1199,7 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeRecognizerPtrHandleTouchUpEventTest001, Tes * @tc.expected: step2. result equals REJECT. */ swipeRecognizerPtr->refereeState_ = RefereeState::DETECTING; - swipeRecognizerPtr->speed_ = -1; + swipeRecognizerPtr->speed_ = Dimension(-1, DimensionUnit::PX); swipeRecognizerPtr->fingers_ = 1; swipeRecognizerPtr->HandleTouchUpEvent(touchEvent); EXPECT_EQ(swipeRecognizerPtr->disposal_, GestureDisposal::REJECT); @@ -1223,7 +1223,8 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureLimitFingerTest001, TestSize.Level1) double speedNum = DEFAULT_SLIDE_SPEED; SwipeDirection slideDirection; SwipeGestureModelNG swipeGestureModelNG; - swipeGestureModelNG.Create(fingersNum, slideDirection, speedNum, IS_LIMIT_FINGER_COUNT); + swipeGestureModelNG.Create( + fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX), IS_LIMIT_FINGER_COUNT); RefPtr gestureProcessor; gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor(); @@ -1231,8 +1232,9 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureLimitFingerTest001, TestSize.Level1) EXPECT_EQ(swipeGestureNG->isLimitFingerCount_, IS_LIMIT_FINGER_COUNT); - SwipeGesture swipeGesture = SwipeGesture(fingersNum, slideDirection, speedNum, IS_LIMIT_FINGER_COUNT); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + SwipeGesture swipeGesture = SwipeGesture( + fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX), IS_LIMIT_FINGER_COUNT); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); EXPECT_EQ(swipeGesture.isLimitFingerCount_, IS_LIMIT_FINGER_COUNT); /** @@ -1278,7 +1280,8 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureLimitFingerTest002, TestSize.Level1) double speedNum = DEFAULT_SLIDE_SPEED; SwipeDirection slideDirection; SwipeGestureModelNG swipeGestureModelNG; - swipeGestureModelNG.Create(fingersNum, slideDirection, speedNum, IS_NOT_LIMIT_FINGER_COUNT); + swipeGestureModelNG.Create( + fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX), IS_NOT_LIMIT_FINGER_COUNT); RefPtr gestureProcessor; gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor(); @@ -1286,8 +1289,9 @@ HWTEST_F(SwipeRecognizerTestNg, SwipeGestureLimitFingerTest002, TestSize.Level1) EXPECT_EQ(swipeGestureNG->isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT); - SwipeGesture swipeGesture = SwipeGesture(fingersNum, slideDirection, speedNum, IS_NOT_LIMIT_FINGER_COUNT); - EXPECT_EQ(swipeGesture.speed_, DEFAULT_SLIDE_SPEED); + SwipeGesture swipeGesture = SwipeGesture( + fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX), IS_NOT_LIMIT_FINGER_COUNT); + EXPECT_EQ(swipeGesture.speed_, Dimension(DEFAULT_SLIDE_SPEED, DimensionUnit::PX)); EXPECT_EQ(swipeGesture.isLimitFingerCount_, IS_NOT_LIMIT_FINGER_COUNT); /** diff --git a/test/unittest/core/gestures/tap_gesture_test_ng.cpp b/test/unittest/core/gestures/tap_gesture_test_ng.cpp index a988a5248433d69e74f556edd5ebf561c09e0e31..e49fd9ce1703980ed1f5c023914b902be952c949 100644 --- a/test/unittest/core/gestures/tap_gesture_test_ng.cpp +++ b/test/unittest/core/gestures/tap_gesture_test_ng.cpp @@ -152,8 +152,8 @@ HWTEST_F(TapGestureTestNg, GestureTest001, TestSize.Level1) fingersNum = DEFAULT_SLIDE_FINGER; double speedNum = DEFAULT_SLIDE_SPEED; SwipeDirection slideDirection; - swipeGestureModelNG.Create(fingersNum, slideDirection, speedNum); + swipeGestureModelNG.Create(fingersNum, slideDirection, Dimension(speedNum, DimensionUnit::PX)); auto swipeGestureNG = AceType::DynamicCast(gestureProcessor->TopGestureNG()); - EXPECT_EQ(swipeGestureNG->speed_, speedNum); + EXPECT_EQ(swipeGestureNG->speed_, Dimension(speedNum, DimensionUnit::PX)); } } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/interfaces/ace_gesture/native_swiper_gesture_test.cpp b/test/unittest/interfaces/ace_gesture/native_swiper_gesture_test.cpp index b9d4f80768c9ee1ef72beed664733dd18e631109..3bceed048c74624cd62b8df5a650e29004a716a9 100644 --- a/test/unittest/interfaces/ace_gesture/native_swiper_gesture_test.cpp +++ b/test/unittest/interfaces/ace_gesture/native_swiper_gesture_test.cpp @@ -150,7 +150,7 @@ HWTEST_F(NativeSwiperGestureTest, NativeSwiperGestureTest003, TestSize.Level1) Ace::NG::SwipeGesture* swipeGesture = reinterpret_cast (swiperGestureRecognizer->gesture); - EXPECT_EQ(swipeGesture->speed_, expectedSpeed); + EXPECT_EQ(swipeGesture->speed_, Dimension(expectedSpeed, DimensionUnit::VP)); NATIVE_GESTURE_API->dispose(swiperGestureRecognizer); }