@@ -41,6 +41,7 @@ For license and copyright information please follow this link:
4141#include " ui/wrap/vertical_layout.h"
4242#include " ui/effects/radial_animation.h"
4343#include " ui/effects/ripple_animation.h"
44+ #include " ui/effects/slide_animation.h"
4445#include " ui/chat/requests_bar.h"
4546#include " ui/chat/group_call_bar.h"
4647#include " ui/chat/more_chats_bar.h"
@@ -447,6 +448,10 @@ Widget::Widget(
447448 _childListPeerId.value (),
448449 _childListShown.value (),
449450 makeChildListShown)));
451+ controller->activeChatsFilter (
452+ ) | rpl::on_next ([=](FilterId id) {
453+ switchToChatsFilter (id);
454+ }, lifetime ());
450455 rpl::combine (
451456 _scroll->heightValue (),
452457 _topBarSuggestionHeightChanged.events_starting_with (0 )
@@ -953,7 +958,9 @@ void Widget::setupSwipeBack() {
953958 if (CheckAndJumpToNearChatsFilter (controller (), next, false )) {
954959 return Ui::Controls::DefaultSwipeBackHandlerFinishData ([=] {
955960 _swipeBackData = {};
961+ _chatsFilterSwipeSwitch = true ;
956962 CheckAndJumpToNearChatsFilter (controller (), next, true );
963+ _chatsFilterSwipeSwitch = false ;
957964 });
958965 }
959966 }
@@ -2052,9 +2059,10 @@ void Widget::toggleFiltersMenu(bool enabled) {
20522059 _chatFilters.get (),
20532060 &session (),
20542061 [this ](FilterId id) {
2055- _scroll->scrollToY (0 );
20562062 if (controller ()->activeChatsFilterCurrent () != id) {
20572063 controller ()->setActiveChatsFilter (id);
2064+ } else {
2065+ _scroll->scrollToY (0 );
20582066 }
20592067 },
20602068 Window::GifPauseReason::Any,
@@ -2246,6 +2254,7 @@ void Widget::changeOpenedSubsection(
22462254 if (isHidden ()) {
22472255 animated = anim::type::instant;
22482256 }
2257+ _chatsFilterSlideCanvas = nullptr ;
22492258 auto oldContentCache = QPixmap ();
22502259 const auto showDirection = fromRight
22512260 ? Window::SlideDirection::FromRight
@@ -2519,6 +2528,84 @@ void Widget::showSearchInTopBar(anim::type animated) {
25192528 updateForceDisplayWide ();
25202529}
25212530
2531+ void Widget::switchToChatsFilter (FilterId id) {
2532+ const auto was = _inner->filterId ();
2533+ const auto animated = (was != id)
2534+ && !isHidden ()
2535+ && !_showAnimation
2536+ && (_chatsFilterSwipeSwitch
2537+ || (_chatFilters && !_chatFilters->isHidden ()));
2538+ if (!animated) {
2539+ _inner->switchToFilter (id);
2540+ return ;
2541+ }
2542+ const auto &list = session ().data ().chatsFilters ().list ();
2543+ const auto indexOf = [&](FilterId filterId) {
2544+ return int (ranges::find (list, filterId, &Data::ChatFilter::id)
2545+ - begin (list));
2546+ };
2547+ const auto slideLeft = (indexOf (id) < indexOf (was));
2548+ const auto duration = _chatsFilterSwipeSwitch
2549+ ? st::dialogsFilterSwipeSlideDuration
2550+ : st::slideDuration;
2551+ _chatsFilterSlideCanvas = nullptr ;
2552+ auto wasCache = grabForChatsFilterSlide ();
2553+ _inner->switchToFilter (id);
2554+ if (_inner->filterId () == was) {
2555+ return ;
2556+ }
2557+ startChatsFilterSlide (
2558+ std::move (wasCache),
2559+ grabForChatsFilterSlide (),
2560+ slideLeft,
2561+ duration);
2562+ }
2563+
2564+ QPixmap Widget::grabForChatsFilterSlide () {
2565+ const auto hidden = _scrollToTop->isHidden ();
2566+ if (!hidden) {
2567+ _scrollToTop->hide ();
2568+ }
2569+ auto result = Ui::GrabOpaque (
2570+ _scroll.data (),
2571+ _scroll->rect (),
2572+ st::dialogsBg->c );
2573+ if (!hidden) {
2574+ _scrollToTop->show ();
2575+ }
2576+ return result;
2577+ }
2578+
2579+ void Widget::startChatsFilterSlide (
2580+ QPixmap wasCache,
2581+ QPixmap nowCache,
2582+ bool slideLeft,
2583+ crl::time duration) {
2584+ _chatsFilterSlideCanvas = std::make_unique<Ui::RpWidget>(this );
2585+ const auto canvas = _chatsFilterSlideCanvas.get ();
2586+ canvas->setAttribute (Qt::WA_TransparentForMouseEvents);
2587+ canvas->setAttribute (Qt::WA_OpaquePaintEvent);
2588+ canvas->setGeometry (_scroll->geometry ());
2589+ const auto animation
2590+ = canvas->lifetime ().make_state <Ui::SlideAnimation>();
2591+ animation->setSnapshots (std::move (wasCache), std::move (nowCache));
2592+ canvas->paintOn ([=](QPainter &p) {
2593+ p.fillRect (canvas->rect (), st::dialogsBg);
2594+ animation->paintFrame (p, 0 , 0 , canvas->width ());
2595+ });
2596+ canvas->show ();
2597+ if (_connecting) {
2598+ _connecting->raise ();
2599+ }
2600+ animation->start (slideLeft, [=] {
2601+ if (animation->animating ()) {
2602+ canvas->update ();
2603+ } else {
2604+ _chatsFilterSlideCanvas = nullptr ;
2605+ }
2606+ }, duration);
2607+ }
2608+
25222609QPixmap Widget::grabForFolderSlideAnimation () {
25232610 const auto hidden = _scrollToTop->isHidden ();
25242611 if (!hidden) {
@@ -2832,6 +2919,7 @@ void Widget::showAnimated(
28322919 Window::SlideDirection direction,
28332920 const Window::SectionSlideParams ¶ms) {
28342921 _showAnimation = nullptr ;
2922+ _chatsFilterSlideCanvas = nullptr ;
28352923
28362924 auto oldContentCache = params.oldContentCache ;
28372925 showFast ();
@@ -4607,6 +4695,9 @@ void Widget::updateControlsGeometry() {
46074695 const auto scrollHeight = height () - scrollTop - bottomSkip;
46084696 const auto wasScrollHeight = _scroll->height ();
46094697 _scroll->setGeometry (0 , scrollTop, scrollWidth, scrollHeight);
4698+ if (_chatsFilterSlideCanvas) {
4699+ _chatsFilterSlideCanvas->setGeometry (_scroll->geometry ());
4700+ }
46104701 if (scrollHeight != wasScrollHeight) {
46114702 controller ()->floatPlayerAreaUpdated ();
46124703 }
0 commit comments