From a73490e5ad6fe2277299aca3d0503e60b198107b Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 27 Jun 2023 19:40:59 +0400 Subject: [PATCH] Add simple scroll control to Hidden Stories. --- Telegram/SourceFiles/boxes/peer_list_box.cpp | 3 + .../boxes/peer_list_controllers.cpp | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 66f10501a2..2ceba422b8 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -1254,6 +1254,9 @@ void PeerListContent::initDecorateWidget(Ui::RpWidget *widget) { }) | rpl::start_with_next([=] { mouseLeftGeometry(); }, widget->lifetime()); + widget->heightValue() | rpl::skip(1) | rpl::start_with_next([=] { + resizeToWidth(width()); + }, widget->lifetime()); } } diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index 1e104b5a36..b1c87eaffb 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -63,6 +63,7 @@ object_ptr PrepareContactsBox( Stories::List *stories = nullptr; QPointer<::Ui::IconButton> toggleSort; Mode mode = ContactsBoxController::SortMode::Online; + ::Ui::Animations::Simple scrollAnimation; }; const auto stories = &sessionController->session().data().stories(); @@ -119,6 +120,66 @@ object_ptr PrepareContactsBox( stories->loadMore(Data::StorySourcesList::Hidden); }, raw->lifetime()); + const auto defaultScrollTop = [=] { + return std::max(raw->height() - st::dialogsStories.height, 0); + }; + const auto scrollToDefault = [=](bool verytop) { + if (state->scrollAnimation.animating()) { + return; + } + if (verytop) { + //_scroll->verticalScrollBar()->setMinimum(0); + } + state->scrollAnimation.stop(); + auto scrollTop = box->scrollTop(); + const auto scrollTo = verytop ? 0 : defaultScrollTop(); + if (scrollTop == scrollTo) { + return; + } + const auto maxAnimatedDelta = box->height(); + if (scrollTo + maxAnimatedDelta < scrollTop) { + scrollTop = scrollTo + maxAnimatedDelta; + box->scrollToY(scrollTop); + } + + const auto scroll = [=] { + const auto animated = qRound( + state->scrollAnimation.value(scrollTo)); + const auto animatedDelta = animated - scrollTo; + const auto realDelta = box->scrollTop() - scrollTo; + if (realDelta * animatedDelta < 0) { + // We scrolled manually to the other side of target 'scrollTo'. + state->scrollAnimation.stop(); + } else if (std::abs(realDelta) > std::abs(animatedDelta)) { + // We scroll by animation only if it gets us closer to target. + box->scrollToY(animated); + } + }; + + state->scrollAnimation.start( + scroll, + scrollTop, + scrollTo, + st::slideDuration, + anim::sineInOut); + }; + const auto top = box->scrollTop(); + raw->toggleExpandedRequests( + ) | rpl::start_with_next([=](bool expanded) { + if (expanded || box->scrollTop() < defaultScrollTop()) { + scrollToDefault(expanded); + } + }, raw->lifetime()); + + raw->heightValue( + ) | rpl::filter([=] { + return (box->scrollHeight() > 0) + && (defaultScrollTop() > box->scrollTop()); + }) | rpl::start_with_next([=] { + //refreshForDefaultScroll(); + box->scrollToY(defaultScrollTop()); + }, raw->lifetime()); + stories->incrementPreloadingHiddenSources(); raw->lifetime().add([=] { stories->decrementPreloadingHiddenSources();