From d93d8ab1cc845e7bd168178959791f2c1bb69858 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 17 Feb 2025 20:00:30 +0300 Subject: [PATCH] Added ability to provide ElasticScroll to SetupSwipeHandler. --- .../history/history_view_swipe.cpp | 28 ++++++++++++------- .../SourceFiles/history/history_view_swipe.h | 8 +++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/history/history_view_swipe.cpp b/Telegram/SourceFiles/history/history_view_swipe.cpp index 7d6c54ca27..866f25d17d 100644 --- a/Telegram/SourceFiles/history/history_view_swipe.cpp +++ b/Telegram/SourceFiles/history/history_view_swipe.cpp @@ -31,7 +31,7 @@ constexpr auto kSwipeSlow = 0.2; void SetupSwipeHandler( not_null widget, - not_null scroll, + Scroll scroll, Fn update, Fn generateFinish, rpl::producer dontStart) { @@ -88,10 +88,15 @@ void SetupSwipeHandler( const auto setOrientation = [=](std::optional o) { state->orientation = o; const auto isHorizontal = (o == Qt::Horizontal); - scroll->viewport()->setAttribute( - Qt::WA_AcceptTouchEvents, - !isHorizontal); - scroll->disableScroll(isHorizontal); + v::match(scroll, [](v::null_t) { + }, [&](const auto &scroll) { + if (const auto viewport = scroll->viewport()) { + viewport->setAttribute( + Qt::WA_AcceptTouchEvents, + !isHorizontal); + } + scroll->disableScroll(isHorizontal); + }); }; const auto processEnd = [=](std::optional delta = {}) { if (state->orientation == Qt::Horizontal) { @@ -120,11 +125,14 @@ void SetupSwipeHandler( state->startAt = {}; state->delta = {}; }; - scroll->scrolls() | rpl::start_with_next([=] { - if (state->orientation != Qt::Vertical) { - processEnd(); - } - }, state->lifetime); + v::match(scroll, [](v::null_t) { + }, [&](const auto &scroll) { + scroll->scrolls() | rpl::start_with_next([=] { + if (state->orientation != Qt::Vertical) { + processEnd(); + } + }, state->lifetime); + }); const auto animationReachCallback = [=](float64 value) { state->data.reachRatio = value; update(state->data); diff --git a/Telegram/SourceFiles/history/history_view_swipe.h b/Telegram/SourceFiles/history/history_view_swipe.h index 300e390402..49d1468b10 100644 --- a/Telegram/SourceFiles/history/history_view_swipe.h +++ b/Telegram/SourceFiles/history/history_view_swipe.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once namespace Ui { +class ElasticScroll; class RpWidget; class ScrollArea; } // namespace Ui @@ -24,9 +25,14 @@ struct SwipeHandlerFinishData { int64 msgBareId = 0; }; +using Scroll = std::variant< + v::null_t, + not_null, + not_null>; + void SetupSwipeHandler( not_null widget, - not_null scroll, + Scroll scroll, Fn update, Fn generateFinishByTop, rpl::producer dontStart = nullptr);