diff --git a/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.cpp b/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.cpp index 3d9d83c449..ac5fc0140a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.cpp @@ -150,8 +150,11 @@ constexpr auto kSugLowCreditsSubs = "STARS_SUBSCRIPTION_LOW_BALANCE"_cs; rpl::producer*> TopBarSuggestionValue( not_null parent, not_null session, - rpl::producer outerWrapToggleValue) { - return [=, outerWrapToggleValue = rpl::duplicate(outerWrapToggleValue)]( + rpl::producer outerWrapToggleValue, + rpl::producer childListShown) { + return [=, + outerWrapToggleValue = rpl::duplicate(outerWrapToggleValue), + childListShown = rpl::duplicate(childListShown)]( auto consumer) { auto lifetime = rpl::lifetime(); @@ -187,12 +190,8 @@ rpl::producer*> TopBarSuggestionValue( parent, [=] { return window->isGifPausedAtLeastFor( Window::GifPauseReason::Layer); }); - rpl::combine( - parent->widthValue(), - state->content->desiredHeightValue() - ) | rpl::on_next([=](int width, int height) { - state->content->resize(width, height); - }, state->content->lifetime()); + state->content->setCollapseProgress( + rpl::duplicate(childListShown)); } }; const auto ensureWrap = [=](not_null child) { diff --git a/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.h b/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.h index 613299988b..cb83206a32 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.h +++ b/Telegram/SourceFiles/dialogs/dialogs_top_bar_suggestion.h @@ -25,7 +25,8 @@ namespace Dialogs { [[nodiscard]] auto TopBarSuggestionValue( not_null parent, not_null, - rpl::producer outerWrapToggleValue) + rpl::producer outerWrapToggleValue, + rpl::producer childListShown) -> rpl::producer*>; } // namespace Dialogs diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index d15aca2f23..401900b166 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1119,7 +1119,11 @@ void Widget::setupTopBarSuggestions() { && !searchInPeer && (id == owner->chatsFilters().defaultId()); }); - return TopBarSuggestionValue(_innerList, &session(), std::move(on)); + return TopBarSuggestionValue( + _innerList, + &session(), + std::move(on), + _childListShown.value()); }) | rpl::flatten_latest() | rpl::on_next([=]( Ui::SlideWrap *raw) { if (raw) { @@ -1130,19 +1134,6 @@ void Widget::setupTopBarSuggestions() { ) | rpl::start_to_stream( _topBarSuggestionHeightChanged, _topBarSuggestion->entity()->lifetime()); - rpl::combine( - _topBarSuggestion->entity()->desiredHeightValue(), - _childListShown.value() - ) | rpl::on_next([=]( - int desiredHeight, - float64 shown) { - const auto newHeight = desiredHeight * (1. - shown); - _topBarSuggestion->entity()->setMaximumHeight(newHeight); - _topBarSuggestion->entity()->setMinimumWidth((shown > 0) - ? width() - : 0); - _topBarSuggestion->entity()->resize(width(), newHeight); - }, _topBarSuggestion->lifetime()); } else { if (_topBarSuggestion) { delete _topBarSuggestion; diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.cpp index 35862b0508..ba7ed63c92 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.cpp @@ -545,7 +545,18 @@ int TopBarSuggestionContent::resizeGetHeight(int newWidth) { natural, st::sponsoredMessageBarMaxHeight); _desiredHeight = capped; - return capped; + return int(base::SafeRound(capped * (1. - _collapseProgress))); +} + +void TopBarSuggestionContent::setCollapseProgress( + rpl::producer progress) { + std::move(progress) | rpl::on_next([=](float64 value) { + if (_collapseProgress == value) { + return; + } + _collapseProgress = value; + resizeToWidth(width()); + }, lifetime()); } void TopBarSuggestionContent::setHideCallback(Fn hideCallback) { diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.h b/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.h index aa746b8fbb..17fa01a972 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.h +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_top_bar_suggestion_content.h @@ -64,6 +64,7 @@ public: rpl::producer text, Fn callback); void setLeftPadding(rpl::producer); + void setCollapseProgress(rpl::producer progress); [[nodiscard]] const style::TextStyle &contentTitleSt() const; @@ -81,6 +82,7 @@ private: Ui::Text::String _contentTitle; Ui::Text::String _contentText; rpl::variable _desiredHeight = 0; + float64 _collapseProgress = 0.; std::optional _descriptionColorOverride; base::unique_qptr _rightHide;