diff --git a/Telegram/SourceFiles/history/view/history_view_summary_header.cpp b/Telegram/SourceFiles/history/view/history_view_summary_header.cpp index 04dc4e4653..9f427f3f6d 100644 --- a/Telegram/SourceFiles/history/view/history_view_summary_header.cpp +++ b/Telegram/SourceFiles/history/view/history_view_summary_header.cpp @@ -43,14 +43,12 @@ SummaryHeader::~SummaryHeader() = default; void SummaryHeader::update(not_null view) { const auto item = view->data(); - using namespace Ui; - _animation = std::make_unique(Animation{ - .particles = StarParticles( - StarParticles::Type::Right, - 15, - st::lineWidth * 8), - }); - _animation->particles.setSpeed(0.05); + if (!_animation) { + ensureAnimation(); + } + if (!_lottie) { + ensureLottie(); + } _text.setText( st::defaultTextStyle, @@ -64,14 +62,6 @@ void SummaryHeader::update(not_null view) { + st::maxSignatureSize / 2 + st::historyReplyPadding.right(); - _lottie = Lottie::MakeIcon(Lottie::IconDescriptor{ - .name = u"cocoon"_q, - .sizeOverride = Size(st::historySummaryHeaderIconSize - - st::historySummaryHeaderIconSizeInner * 2), - .color = &st::attentionButtonFg, - .colorizeUsingAlpha = true, - }); - const auto session = &item->history()->session(); const auto itemId = item->fullId(); _link = std::make_shared([=](ClickContext context) { @@ -140,7 +130,10 @@ void SummaryHeader::paint( cache->bg = rippleColor; } - if (_lottie) { + if (!_lottie) { + ensureLottie(); + } + { const auto r = iconRect().translated(x, y); const auto lottieX = r.x() + st::historySummaryHeaderIconSizeInner; const auto lottieY = r.y() + st::historySummaryHeaderIconSizeInner; @@ -159,7 +152,10 @@ void SummaryHeader::paint( } } - if (_animation) { + if (!_animation) { + ensureAnimation(); + } + { const auto size = QSize(w, _height); if (_animation->cachedSize != size) { _animation->path = QPainterPath(); @@ -287,6 +283,7 @@ void SummaryHeader::stopLastRipple() { } void SummaryHeader::unloadHeavyPart() { + _unloadTime = crl::now(); _animation = nullptr; _ripple.animation = nullptr; _iconRipple.animation = nullptr; @@ -299,4 +296,25 @@ QRect SummaryHeader::iconRect() const { return QRect(_width - size - shift, (_height - size) / 2, size, size); } +void SummaryHeader::ensureAnimation() const { + using namespace Ui; + _animation = std::make_unique(Animation{ + .particles = StarParticles( + StarParticles::Type::Right, + 15, + st::lineWidth * 8), + }); + _animation->particles.setSpeed(0.05); +} + +void SummaryHeader::ensureLottie() const { + _lottie = Lottie::MakeIcon(Lottie::IconDescriptor{ + .name = u"cocoon"_q, + .sizeOverride = Size(st::historySummaryHeaderIconSize + - st::historySummaryHeaderIconSizeInner * 2), + .color = &st::attentionButtonFg, + .colorizeUsingAlpha = true, + }); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_summary_header.h b/Telegram/SourceFiles/history/view/history_view_summary_header.h index 28d6497354..d9f37050ea 100644 --- a/Telegram/SourceFiles/history/view/history_view_summary_header.h +++ b/Telegram/SourceFiles/history/view/history_view_summary_header.h @@ -53,6 +53,9 @@ public: void unloadHeavyPart(); private: + void ensureAnimation() const; + void ensureLottie() const; + [[nodiscard]] QRect iconRect() const; struct Animation { Ui::StarParticles particles; @@ -61,7 +64,7 @@ private: }; ClickHandlerPtr _link; - std::unique_ptr _animation; + mutable std::unique_ptr _animation; mutable struct { mutable std::unique_ptr animation; QPoint lastPoint; @@ -75,7 +78,8 @@ private: mutable int _maxWidth = 0; mutable int _height = 0; mutable int _width = 0; - std::unique_ptr _lottie; + mutable std::unique_ptr _lottie; + mutable crl::time _unloadTime = 0; };