From 38d04bf77dda1301a75634922d76d8389e4aacb0 Mon Sep 17 00:00:00 2001 From: yangziyong Date: Wed, 10 Apr 2024 17:13:23 +0800 Subject: [PATCH] Make text view not marquee when visble is false Signed-off-by: yangziyong --- .../pattern/text/text_content_modifier.cpp | 27 ++++++++++++++++ .../pattern/text/text_content_modifier.h | 4 +++ .../pattern/text/text_pattern.cpp | 31 +++++++++++++++++++ .../components_ng/pattern/text/text_pattern.h | 3 ++ 4 files changed, 65 insertions(+) diff --git a/frameworks/core/components_ng/pattern/text/text_content_modifier.cpp b/frameworks/core/components_ng/pattern/text/text_content_modifier.cpp index 15385860302..ed1897ee12b 100644 --- a/frameworks/core/components_ng/pattern/text/text_content_modifier.cpp +++ b/frameworks/core/components_ng/pattern/text/text_content_modifier.cpp @@ -274,6 +274,9 @@ void TextContentModifier::DrawImageNodeList(const float drawingContextWidth, void TextContentModifier::onDraw(DrawingContext& drawingContext) { ACE_SCOPED_TRACE("Text::onDraw"); + if (!visible_) { + return; + } bool ifPaintObscuration = std::any_of(obscuredReasons_.begin(), obscuredReasons_.end(), [](const auto& reason) { return reason == ObscuredReasons::PLACEHOLDER; }); if (!ifPaintObscuration || ifHaveSpanItemChildren_) { @@ -813,6 +816,30 @@ void TextContentModifier::StopTextRace() racePercentFloat_->Set(RACE_MOVE_PERCENT_MIN); } +void TextContentModifier::PauseTextRace() +{ + if (!textRacing_) { + return; + } + + if (raceAnimation_) { + AnimationUtils::PauseAnimation(raceAnimation_); + visible_ = false; + } +} + +void TextContentModifier::ResumeTextRace() +{ + if (!textRacing_) { + return; + } + + if (raceAnimation_) { + AnimationUtils::ResumeAnimation(raceAnimation_); + visible_ = true; + } +} + float TextContentModifier::GetTextRacePercent() { float percent = 0; diff --git a/frameworks/core/components_ng/pattern/text/text_content_modifier.h b/frameworks/core/components_ng/pattern/text/text_content_modifier.h index 93093ca4789..d8c9f3f979d 100644 --- a/frameworks/core/components_ng/pattern/text/text_content_modifier.h +++ b/frameworks/core/components_ng/pattern/text/text_content_modifier.h @@ -94,6 +94,9 @@ public: { imageNodeList_ = imageNodeList; } + + void PauseTextRace(); + void ResumeTextRace(); protected: OffsetF GetPaintOffset() const { @@ -175,6 +178,7 @@ private: RefPtr baselineOffsetFloat_; bool textRacing_ = false; + bool visible_ = true; int32_t marqueeCount_ = 0; WeakPtr pattern_; double marqueeStep_ = 1; diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.cpp b/frameworks/core/components_ng/pattern/text/text_pattern.cpp index 1839f0d51a8..f5083c940c0 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text/text_pattern.cpp @@ -96,6 +96,7 @@ void TextPattern::OnDetachFromFrameNode(FrameNode* node) fontManager->RemoveVariationNodeNG(frameNode); } pipeline->RemoveOnAreaChangeNode(node->GetId()); + pipeline->RemoveVisibleAreaChangeNode(node->GetId()); } void TextPattern::CloseSelectOverlay() @@ -1811,6 +1812,7 @@ void TextPattern::OnModifyDone() CloseSelectOverlay(); ResetSelection(); copyOption_ = CopyOptions::None; + RegisterVisibleAreaChangeCallback(); } else { copyOption_ = textLayoutProperty->GetCopyOption().value_or(CopyOptions::None); } @@ -2894,4 +2896,33 @@ void TextPattern::UpdateSpanItems(const std::list>& spanItems) CHECK_NULL_VOID(host); host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } + +void TextPattern::RegisterVisibleAreaChangeCallback() +{ + if (isRegisteredAreaCallback_) { + return; + } + isRegisteredAreaCallback_ = true; + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto callback = [weak = WeakClaim(this)](bool visible, double ratio) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->OnVisibleAreaChange(visible); + }; + std::vector ratioList = {0.0}; + pipeline->AddVisibleAreaChangeNode(host, ratioList, callback, false); +} + +void TextPattern::OnVisibleAreaChange(bool visible) +{ + CHECK_NULL_VOID(contentMod_); + if (visible) { + contentMod_->ResumeTextRace(); + } else { + contentMod_->PauseTextRace(); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.h b/frameworks/core/components_ng/pattern/text/text_pattern.h index 6f72c3c937a..b7dac375ebf 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.h +++ b/frameworks/core/components_ng/pattern/text/text_pattern.h @@ -660,6 +660,8 @@ private: void ProcessBoundRectByTextMarquee(RectF& rect); ResultObject GetBuilderResultObject(RefPtr uiNode, int32_t index, int32_t start, int32_t end); void CreateModifier(); + void RegisterVisibleAreaChangeCallback(); + void OnVisibleAreaChange(bool visible); bool IsLineBreakOrEndOfParagraph(int32_t pos) const; void ToJsonValue(std::unique_ptr& json) const override; @@ -710,6 +712,7 @@ private: std::function processOverlayDelayTask_; RefPtr selectOverlay_; std::vector> imageNodeList_; + bool isRegisteredAreaCallback_ = false; ACE_DISALLOW_COPY_AND_MOVE(TextPattern); }; } // namespace OHOS::Ace::NG -- Gitee