diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp index 25ed5ab01dbab60eb700576f8270cffab38ef0f5..04b696e77f2aed5a917f3c53f460dd5ea222562a 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) {