From a41fb6387dd86e17e8ee3e4238d3cabc73065b98 Mon Sep 17 00:00:00 2001 From: yeyinglong Date: Thu, 27 Jul 2023 11:34:32 +0800 Subject: [PATCH] =?UTF-8?q?scrollTo=20=E5=8A=A8=E7=94=BB=E6=94=AF=E6=8C=81?= =?UTF-8?q?Curves.springMotion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yeyinglong --- .../pattern/scrollable/scrollable_pattern.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp index 25ed5ab01db..04b696e77f2 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp @@ -502,7 +502,12 @@ void ScrollablePattern::ScrollTo(float position) void ScrollablePattern::AnimateTo(float position, float duration, const RefPtr& curve, bool smooth) { LOGI("AnimateTo:%f, duration:%f", position, duration); + float currVelocity = 0.0f; if (!IsScrollableStopped()) { + CHECK_NULL_VOID(scrollableEvent_); + auto scrollable = scrollableEvent_->GetScrollable(); + CHECK_NULL_VOID(scrollable); + currVelocity = -scrollable->GetCurrentVelocity(); scrollAbort_ = true; StopScrollable(); } @@ -514,6 +519,9 @@ void ScrollablePattern::AnimateTo(float position, float duration, const RefPtrOnAnimateStop(); }); } else if (!animator_->IsStopped()) { + if (springMotion_) { + currVelocity = springMotion_->GetCurrentVelocity(); + } scrollAbort_ = true; animator_->Stop(); } @@ -529,6 +537,13 @@ void ScrollablePattern::AnimateTo(float position, float duration, const RefPtrGetStiffness(); float damping = springCurve->GetDamping(); PlaySpringAnimation(position, velocity, mass, stiffness, damping); + } else if (AceType::InstanceOf(curve)) { + auto springCurve = AceType::DynamicCast(curve); + constexpr float PI = 3.1415926f; + float tmpStiffness = (2 * PI / springCurve->GetResponse()); + float stiffness = tmpStiffness * tmpStiffness; + float damping = 4 * PI * springCurve->GetDampingRatio() / springCurve->GetResponse(); + PlaySpringAnimation(position, currVelocity, 1.0f, stiffness, damping); } else { auto animation = AceType::MakeRefPtr>(GetTotalOffset(), position, curve); animation->AddListener([weakScroll = AceType::WeakClaim(this)](float value) { -- Gitee