Fixed double scroll in reactions settings when height is small.

This commit is contained in:
23rd 2022-05-01 02:38:49 +03:00
parent 4c6814def6
commit 2f5db08c9b
1 changed files with 24 additions and 41 deletions

View File

@ -89,12 +89,13 @@ AdminLog::OwnedItem GenerateItem(
} }
void AddMessage( void AddMessage(
not_null<Ui::GenericBox*> box, not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
rpl::producer<QString> &&emojiValue) { rpl::producer<QString> &&emojiValue,
int width) {
const auto widget = box->addRow( const auto widget = container->add(
object_ptr<Ui::RpWidget>(box), object_ptr<Ui::RpWidget>(container),
style::margins( style::margins(
0, 0,
st::settingsSectionSkip, st::settingsSectionSkip,
@ -121,7 +122,7 @@ void AddMessage(
bool flag = false; bool flag = false;
} icons; } icons;
}; };
const auto state = box->lifetime().make_state<State>(); const auto state = container->lifetime().make_state<State>();
state->delegate = std::make_unique<Delegate>( state->delegate = std::make_unique<Delegate>(
controller, controller,
crl::guard(widget, [=] { widget->update(); })); crl::guard(widget, [=] { widget->update(); }));
@ -150,16 +151,18 @@ void AddMessage(
const auto padding = st::settingsForwardPrivacyPadding; const auto padding = st::settingsForwardPrivacyPadding;
widget->widthValue( const auto updateWidgetSize = [=](int width) {
) | rpl::filter(
rpl::mappers::_1 >= (st::historyMinimalWidth / 2)
) | rpl::start_with_next([=](int width) {
const auto height = view->resizeGetHeight(width); const auto height = view->resizeGetHeight(width);
const auto top = view->marginTop(); const auto top = view->marginTop();
const auto bottom = view->marginBottom(); const auto bottom = view->marginBottom();
const auto full = padding + top + height + bottom + padding; const auto full = padding + top + height + bottom + padding;
widget->resize(width, full); 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 rightSize = st::settingsReactionCornerSize;
const auto rightRect = [=] { const auto rightRect = [=] {
@ -224,7 +227,7 @@ void AddMessage(
const auto index = state->icons.flag ? 1 : 0; const auto index = state->icons.flag ? 1 : 0;
state->icons.lifetimes[index] = rpl::lifetime(); state->icons.lifetimes[index] = rpl::lifetime();
AddReactionLottieIcon( AddReactionLottieIcon(
box->verticalLayout(), container,
widget->geometryValue( widget->geometryValue(
) | rpl::map([=](const QRect &r) { ) | rpl::map([=](const QRect &r) {
return widget->pos() return widget->pos()
@ -388,34 +391,19 @@ void ReactionsSettingsBox(
const auto state = box->lifetime().make_state<State>(); const auto state = box->lifetime().make_state<State>();
state->selectedEmoji = reactions.favorite(); state->selectedEmoji = reactions.favorite();
AddMessage(box, controller, state->selectedEmoji.value()); const auto pinnedToTop = box->setPinnedToTopContent(
object_ptr<Ui::VerticalLayout>(box));
auto emojiValue = state->selectedEmoji.value();
AddMessage(pinnedToTop, controller, std::move(emojiValue), box->width());
const auto container = box->verticalLayout();
Settings::AddSubsectionTitle( Settings::AddSubsectionTitle(
container, pinnedToTop,
tr::lng_settings_chat_reactions_subtitle()); tr::lng_settings_chat_reactions_subtitle());
const auto &stButton = st::settingsButton; const auto container = box->verticalLayout();
const auto scrollContainer = box->addRow(
object_ptr<Ui::FixedHeightWidget>(
box,
kVisibleButtonsCount
* (stButton.height
+ stButton.padding.top()
+ stButton.padding.bottom())),
style::margins());
const auto scroll = Ui::CreateChild<Ui::ScrollArea>(
scrollContainer,
st::boxScroll);
const auto buttonsContainer = scroll->setOwnedWidget(
object_ptr<Ui::VerticalLayout>(scroll));
scrollContainer->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
scroll->resize(s.width(), s.height());
buttonsContainer->resizeToWidth(s.width());
}, scroll->lifetime());
const auto check = Ui::CreateChild<Ui::RpWidget>(buttonsContainer.data()); const auto check = Ui::CreateChild<Ui::RpWidget>(container.get());
check->resize(st::settingsReactionCornerSize); check->resize(st::settingsReactionCornerSize);
check->setAttribute(Qt::WA_TransparentForMouseEvents); check->setAttribute(Qt::WA_TransparentForMouseEvents);
check->paintRequest( check->paintRequest(
@ -432,9 +420,9 @@ void ReactionsSettingsBox(
auto firstCheckedButton = (Ui::RpWidget*)(nullptr); auto firstCheckedButton = (Ui::RpWidget*)(nullptr);
for (const auto &r : reactions.list(Data::Reactions::Type::Active)) { for (const auto &r : reactions.list(Data::Reactions::Type::Active)) {
const auto button = Settings::AddButton( const auto button = Settings::AddButton(
buttonsContainer, container,
rpl::single<QString>(base::duplicate(r.title)), rpl::single<QString>(base::duplicate(r.title)),
stButton); st::settingsButton);
const auto iconSize = st::settingsReactionSize; const auto iconSize = st::settingsReactionSize;
AddReactionLottieIcon( AddReactionLottieIcon(
@ -472,11 +460,6 @@ void ReactionsSettingsBox(
} }
check->raise(); check->raise();
Ui::SetupShadowsToScrollContent(
scrollContainer,
scroll,
buttonsContainer->heightValue());
box->setTitle(tr::lng_settings_chat_reactions_title()); box->setTitle(tr::lng_settings_chat_reactions_title());
box->setWidth(st::boxWideWidth); box->setWidth(st::boxWideWidth);
box->addButton(tr::lng_settings_save(), [=] { box->addButton(tr::lng_settings_save(), [=] {