From 2f5db08c9bd7112ec8a9c361fabf0478380426d8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 1 May 2022 02:38:49 +0300 Subject: [PATCH] Fixed double scroll in reactions settings when height is small. --- .../boxes/reactions_settings_box.cpp | 65 +++++++------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp index 0c479cb56..8c0bbe550 100644 --- a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp @@ -89,12 +89,13 @@ AdminLog::OwnedItem GenerateItem( } void AddMessage( - not_null box, + not_null container, not_null controller, - rpl::producer &&emojiValue) { + rpl::producer &&emojiValue, + int width) { - const auto widget = box->addRow( - object_ptr(box), + const auto widget = container->add( + object_ptr(container), style::margins( 0, st::settingsSectionSkip, @@ -121,7 +122,7 @@ void AddMessage( bool flag = false; } icons; }; - const auto state = box->lifetime().make_state(); + const auto state = container->lifetime().make_state(); state->delegate = std::make_unique( controller, crl::guard(widget, [=] { widget->update(); })); @@ -150,16 +151,18 @@ void AddMessage( const auto padding = st::settingsForwardPrivacyPadding; - widget->widthValue( - ) | rpl::filter( - rpl::mappers::_1 >= (st::historyMinimalWidth / 2) - ) | rpl::start_with_next([=](int width) { + const auto updateWidgetSize = [=](int width) { const auto height = view->resizeGetHeight(width); const auto top = view->marginTop(); const auto bottom = view->marginBottom(); const auto full = padding + top + height + bottom + padding; widget->resize(width, full); - }, widget->lifetime()); + }; + widget->widthValue( + ) | rpl::filter( + rpl::mappers::_1 >= (st::historyMinimalWidth / 2) + ) | rpl::start_with_next(updateWidgetSize, widget->lifetime()); + updateWidgetSize(width); const auto rightSize = st::settingsReactionCornerSize; const auto rightRect = [=] { @@ -224,7 +227,7 @@ void AddMessage( const auto index = state->icons.flag ? 1 : 0; state->icons.lifetimes[index] = rpl::lifetime(); AddReactionLottieIcon( - box->verticalLayout(), + container, widget->geometryValue( ) | rpl::map([=](const QRect &r) { return widget->pos() @@ -388,34 +391,19 @@ void ReactionsSettingsBox( const auto state = box->lifetime().make_state(); state->selectedEmoji = reactions.favorite(); - AddMessage(box, controller, state->selectedEmoji.value()); + const auto pinnedToTop = box->setPinnedToTopContent( + object_ptr(box)); + + auto emojiValue = state->selectedEmoji.value(); + AddMessage(pinnedToTop, controller, std::move(emojiValue), box->width()); - const auto container = box->verticalLayout(); Settings::AddSubsectionTitle( - container, + pinnedToTop, tr::lng_settings_chat_reactions_subtitle()); - const auto &stButton = st::settingsButton; - const auto scrollContainer = box->addRow( - object_ptr( - box, - kVisibleButtonsCount - * (stButton.height - + stButton.padding.top() - + stButton.padding.bottom())), - style::margins()); - const auto scroll = Ui::CreateChild( - scrollContainer, - st::boxScroll); - const auto buttonsContainer = scroll->setOwnedWidget( - object_ptr(scroll)); - scrollContainer->sizeValue( - ) | rpl::start_with_next([=](const QSize &s) { - scroll->resize(s.width(), s.height()); - buttonsContainer->resizeToWidth(s.width()); - }, scroll->lifetime()); + const auto container = box->verticalLayout(); - const auto check = Ui::CreateChild(buttonsContainer.data()); + const auto check = Ui::CreateChild(container.get()); check->resize(st::settingsReactionCornerSize); check->setAttribute(Qt::WA_TransparentForMouseEvents); check->paintRequest( @@ -432,9 +420,9 @@ void ReactionsSettingsBox( auto firstCheckedButton = (Ui::RpWidget*)(nullptr); for (const auto &r : reactions.list(Data::Reactions::Type::Active)) { const auto button = Settings::AddButton( - buttonsContainer, + container, rpl::single(base::duplicate(r.title)), - stButton); + st::settingsButton); const auto iconSize = st::settingsReactionSize; AddReactionLottieIcon( @@ -472,11 +460,6 @@ void ReactionsSettingsBox( } check->raise(); - Ui::SetupShadowsToScrollContent( - scrollContainer, - scroll, - buttonsContainer->heightValue()); - box->setTitle(tr::lng_settings_chat_reactions_title()); box->setWidth(st::boxWideWidth); box->addButton(tr::lng_settings_save(), [=] {