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 1538586030210b53827dbe6a4bc1a249a1913076..ed1897ee12bb448d96700eeeb5899abf5ae07146 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 93093ca4789a4d92f487d3844933aa84e2b75d09..d8c9f3f979d8f4641d7c49b950de37a2e69f9e17 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 1839f0d51a8ef16d81321d42cb0b200aa5696b83..f5083c940c02f53fd78133a7d6dc982a32179165 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 6f72c3c937a2cd554d01acab55f25319e65b49e3..b7dac375ebf3f5ee9f10acf047c3444af1cef78d 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