From ba4d5611578f2fcb5ae5e12258acf540cc5ed8d2 Mon Sep 17 00:00:00 2001 From: zhangjie Date: Tue, 12 Dec 2023 15:14:07 +0800 Subject: [PATCH] =?UTF-8?q?scrollable=E6=8A=9B=E6=BB=91=20=E9=80=82?= =?UTF-8?q?=E9=85=8DLTPO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangjie Change-Id: I494e7e1c9f6d90709d56bbe2fcd2459e63739b12 --- .../core/components/scroll/scrollable.cpp | 36 +++++++++++++++++++ .../core/components/scroll/scrollable.h | 7 ++++ .../pattern/scrollable/scrollable_pattern.cpp | 16 +++++++++ 3 files changed, 59 insertions(+) diff --git a/frameworks/core/components/scroll/scrollable.cpp b/frameworks/core/components/scroll/scrollable.cpp index 148a2b8a789..cc4b74758f4 100644 --- a/frameworks/core/components/scroll/scrollable.cpp +++ b/frameworks/core/components/scroll/scrollable.cpp @@ -718,6 +718,9 @@ void Scrollable::StartScrollAnimation(float mainPosition, float correctVelocity) } } }); + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(motion_->GetCurrentVelocity(), NG::SceneStatus::START); + } controller_->PlayMotion(motion_); } @@ -844,6 +847,9 @@ void Scrollable::StartScrollSnapMotion(float predictSnapOffset, float scrollSnap CHECK_NULL_VOID(scroll); scroll->ProcessScrollSnapStop(); }); + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(scrollSnapMotion_->GetCurrentVelocity(), NG::SceneStatus::START); + } scrollSnapController_->PlayMotion(scrollSnapMotion_); } @@ -879,6 +885,9 @@ void Scrollable::ProcessScrollSnapSpringMotion(float scrollSnapDelta, float scro } else { snapMotion_->Reset(currentPos_, scrollSnapDelta + currentPos_, scrollSnapVelocity, DEFAULT_OVER_SPRING_PROPERTY); } + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(snapMotion_->GetCurrentVelocity(), NG::SceneStatus::START); + } snapController_->PlayMotion(snapMotion_); } @@ -905,6 +914,9 @@ void Scrollable::ProcessScrollSnapMotion(double position) TAG_LOGD(AceLogTag::ACE_SCROLLABLE, "Current Pos is %{public}lf, position is %{public}lf", currentPos_, position); currentVelocity_ = scrollSnapMotion_->GetCurrentVelocity(); + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(currentVelocity_, NG::SceneStatus::RUNNING); + } if (NearEqual(currentPos_, position)) { UpdateScrollPosition(0.0, SCROLL_FROM_ANIMATION_SPRING); } else { @@ -928,6 +940,9 @@ void Scrollable::ProcessScrollSnapMotion(double position) void Scrollable::ProcessScrollSnapStop() { + if (scrollSnapMotion_ && scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(scrollSnapMotion_->GetCurrentVelocity(), NG::SceneStatus::END); + } if (scrollPause_) { scrollPause_ = false; HandleOverScroll(currentVelocity_); @@ -938,6 +953,9 @@ void Scrollable::ProcessScrollSnapStop() void Scrollable::OnAnimateStop() { + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(scrollMotion_->GetCurrentVelocity(), NG::SceneStatus::END); + } if (moved_) { HandleScrollEnd(); } @@ -987,6 +1005,9 @@ void Scrollable::StartSpringMotion( }); currentPos_ = mainPosition; springController_->ClearStopListeners(); + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(scrollMotion_->GetCurrentVelocity(), NG::SceneStatus::START); + } springController_->PlayMotion(scrollMotion_); springController_->AddStopListener([weak = AceType::WeakClaim(this)]() { auto scroll = weak.Upgrade(); @@ -997,6 +1018,12 @@ void Scrollable::StartSpringMotion( void Scrollable::ProcessScrollMotionStop() { + if (motion_ && scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(motion_->GetCurrentVelocity(), NG::SceneStatus::END); + } + if (snapMotion_ && scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(snapMotion_->GetCurrentVelocity(), NG::SceneStatus::END); + } if (needScrollSnapChange_ && calePredictSnapOffsetCallback_ && motion_) { needScrollSnapChange_ = false; auto predictSnapOffset = calePredictSnapOffsetCallback_(motion_->GetFinalPosition() - currentPos_); @@ -1036,6 +1063,9 @@ void Scrollable::ProcessSpringMotion(double position) TAG_LOGD(AceLogTag::ACE_SCROLLABLE, "Current Pos is %{public}lf, position is %{public}lf", currentPos_, position); currentVelocity_ = scrollMotion_->GetCurrentVelocity(); + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(currentVelocity_, NG::SceneStatus::RUNNING); + } if (NearEqual(currentPos_, position)) { UpdateScrollPosition(0.0, SCROLL_FROM_ANIMATION_SPRING); } else { @@ -1057,6 +1087,12 @@ void Scrollable::ProcessScrollMotion(double position) if (motion_) { currentVelocity_ = motion_->GetCurrentVelocity(); } + if (scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(currentVelocity_, NG::SceneStatus::RUNNING); + } + if (snapMotion_ && scrollMotionFRCSceneCallback_) { + scrollMotionFRCSceneCallback_(snapMotion_->GetCurrentVelocity(), NG::SceneStatus::RUNNING); + } if (needScrollSnapToSideCallback_) { needScrollSnapChange_ = needScrollSnapToSideCallback_(position - currentPos_); } diff --git a/frameworks/core/components/scroll/scrollable.h b/frameworks/core/components/scroll/scrollable.h index 6dcdce0ff89..8e10aa337af 100644 --- a/frameworks/core/components/scroll/scrollable.h +++ b/frameworks/core/components/scroll/scrollable.h @@ -65,6 +65,7 @@ using CalePredictSnapOffsetCallback = std::function(float d using NeedScrollSnapToSideCallback = std::function; using NestableScrollCallback = std::function; using DragFRCSceneCallback = std::function; +using ScrollMotionFRCSceneCallback = std::function; class Scrollable : public TouchEventTarget, public RelatedChild { DECLARE_ACE_TYPE(Scrollable, TouchEventTarget); @@ -467,6 +468,11 @@ public: dragFRCSceneCallback_ = std::move(dragFRCSceneCallback); } + void SetScrollMotionFRCSceneCallback(ScrollMotionFRCSceneCallback&& scrollMotionFRCSceneCallback) + { + scrollMotionFRCSceneCallback_ = std::move(scrollMotionFRCSceneCallback); + } + private: bool UpdateScrollPosition(double offset, int32_t source) const; void ProcessSpringMotion(double position); @@ -561,6 +567,7 @@ private: GestureEventFunc actionEnd_; DragFRCSceneCallback dragFRCSceneCallback_; + ScrollMotionFRCSceneCallback scrollMotionFRCSceneCallback_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp index 325f7d28fda..778e650f5a0 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_pattern.cpp @@ -35,6 +35,8 @@ constexpr Color SELECT_FILL_COLOR = Color(0x1A000000); constexpr Color SELECT_STROKE_COLOR = Color(0x33FFFFFF); const std::string SCROLLABLE_DRAG_SCENE = "scrollable_drag_scene"; const std::string SCROLL_BAR_DRAG_SCENE = "scrollBar_drag_scene"; +const std::string SCROLLABLE_MOTION_SCENE = "scrollable_motion_scene"; +const std::string SCROLLABLE_MULTI_TASK_SCENE = "scrollable_multi_task_scene"; } // namespace RefPtr ScrollablePattern::CreatePaintProperty() @@ -410,6 +412,13 @@ void ScrollablePattern::AddScrollEvent() }; scrollable->SetDragFRCSceneCallback(std::move(dragFRCSceneCallback)); + auto scrollMotionFRCSceneCallback = [weak = WeakClaim(this)](double velocity, SceneStatus sceneStatus) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + return pattern->NotifyFRCSceneInfo(SCROLLABLE_MOTION_SCENE, velocity, sceneStatus); + }; + scrollable->SetScrollMotionFRCSceneCallback(std::move(scrollMotionFRCSceneCallback)); + scrollableEvent_ = MakeRefPtr(GetAxis()); scrollableEvent_->SetScrollable(scrollable); gestureHub->AddScrollableEvent(scrollableEvent_); @@ -842,6 +851,10 @@ void ScrollablePattern::AnimateTo(float position, float duration, const RefPtrAddStopListener([weak = AceType::WeakClaim(this)]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); + if (pattern->springMotion_) { + pattern->NotifyFRCSceneInfo(SCROLLABLE_MULTI_TASK_SCENE, pattern->springMotion_->GetCurrentVelocity(), + SceneStatus::END); + } pattern->OnAnimateStop(); }); } else if (!animator_->IsStopped()) { @@ -914,10 +927,13 @@ void ScrollablePattern::PlaySpringAnimation(float position, float velocity, floa springMotion_->AddListener([weakScroll = AceType::WeakClaim(this)](double position) { auto pattern = weakScroll.Upgrade(); CHECK_NULL_VOID(pattern); + pattern->NotifyFRCSceneInfo(SCROLLABLE_MULTI_TASK_SCENE, pattern->springMotion_->GetCurrentVelocity(), + SceneStatus::RUNNING); if (!pattern->UpdateCurrentOffset(pattern->GetTotalOffset() - position, SCROLL_FROM_ANIMATION_CONTROLLER)) { pattern->animator_->Stop(); } }); + NotifyFRCSceneInfo(SCROLLABLE_MULTI_TASK_SCENE, springMotion_->GetCurrentVelocity(), SceneStatus::START); animator_->PlayMotion(springMotion_); } -- Gitee