From 7fb8be5a37c2fb1abc6bd0f45e59d00515e662bb Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 11 Jul 2026 18:28:12 +0300 Subject: [PATCH] Added swipe interceptor to info content widget. --- .../SourceFiles/info/info_content_widget.cpp | 25 +++++++++++++++++-- .../SourceFiles/info/info_content_widget.h | 6 +++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 4336baa47f..dfa1941a93 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -520,11 +520,15 @@ void ContentWidget::replaceSwipeHandler( Ui::Controls::SetupSwipeHandler(std::move(args)); } +void ContentWidget::setSwipeInterceptor(SwipeInterceptor interceptor) { + _swipeInterceptor = std::move(interceptor); +} + void ContentWidget::setupSwipeHandler(not_null widget) { _swipeHandlerLifetime.destroy(); auto update = [=](Ui::Controls::SwipeContextData data) { - if (data.translation > 0) { + if (data.translation != 0) { if (!_swipeBackData.callback) { _swipeBackData = Ui::Controls::SetupSwipeBack( this, @@ -533,7 +537,8 @@ void ContentWidget::setupSwipeHandler(not_null widget) { st::historyForwardChooseBg->c, st::historyForwardChooseFg->c, }; - }); + }, + data.translation < 0); } _swipeBackData.callback(data); return; @@ -543,6 +548,22 @@ void ContentWidget::setupSwipeHandler(not_null widget) { }; auto init = [=](Ui::Controls::SwipeHandlerInitData data) { + if (_swipeInterceptor) { + auto mapped = data; + mapped.cursorPosition = _innerWrap->entity()->mapFrom( + _innerWrap, + data.cursorPosition); + auto result = _swipeInterceptor(mapped); + if (result.callback) { + result.callback = crl::guard( + this, + [this, onstack = std::move(result.callback)] { + _swipeBackData = {}; + onstack(); + }); + return result; + } + } if (data.direction != Qt::RightToLeft) { return Ui::Controls::SwipeHandlerFinishData(); } diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index 592e178a2f..f671c4e7f1 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_flexible_scroll.h" #include "info/info_wrap_widget.h" #include "info/statistics/info_statistics_tag.h" +#include "ui/controls/swipe_handler.h" #include "ui/controls/swipe_handler_data.h" namespace Api { @@ -162,6 +163,10 @@ public: void replaceSwipeHandler(Ui::Controls::SwipeHandlerArgs *incompleteArgs); + using SwipeInterceptor = Fn; + void setSwipeInterceptor(SwipeInterceptor interceptor); + protected: template Widget *setInnerWidget(object_ptr inner) { @@ -247,6 +252,7 @@ private: style::margins _paintPadding; Ui::Controls::SwipeBackResult _swipeBackData; + SwipeInterceptor _swipeInterceptor; rpl::lifetime _swipeHandlerLifetime; };