From fd718dfd5c8be017ef89906a859cbeb254128a28 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 12 Mar 2025 18:01:47 +0400 Subject: [PATCH] Allow more Info sections swipe-back. --- .../SourceFiles/info/info_content_widget.cpp | 26 ++++++------------- Telegram/SourceFiles/info/info_controller.cpp | 4 +++ Telegram/SourceFiles/info/info_controller.h | 1 + Telegram/SourceFiles/info/info_wrap_widget.h | 2 +- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 499ebb16fb..e0d0cf3eee 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -404,24 +404,14 @@ void ContentWidget::setupSwipeReply() { _swipeBackData = {}; } }, [=](int, Qt::LayoutDirection direction) { - const auto can = [&] { - using Type = Section::Type; - if (direction != Qt::RightToLeft) { - return false; - } else if (_controller->wrap() == Wrap::Side) { - return (_controller->section().type() != Type::Profile); - } else if (_controller->wrap() == Wrap::Narrow) { - return true; - } else { - return false; - } - }(); - - return !can - ? Ui::Controls::SwipeHandlerFinishData() - : Ui::Controls::DefaultSwipeBackHandlerFinishData([=] { - _controller->showBackFromStack(); - }); + return (direction == Qt::RightToLeft && _controller->hasBackButton()) + ? Ui::Controls::DefaultSwipeBackHandlerFinishData([=] { + checkBeforeClose(crl::guard(this, [=] { + _controller->parentController()->hideLayer(); + _controller->showBackFromStack(); + })); + }) + : Ui::Controls::SwipeHandlerFinishData(); }, nullptr); } diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index dc51c31e15..b1ec130dc5 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -358,6 +358,10 @@ void Controller::setSection(not_null memento) { updateSearchControllers(memento); } +bool Controller::hasBackButton() const { + return _widget->hasBackButton(); +} + void Controller::updateSearchControllers( not_null memento) { using Type = Section::Type; diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index 9815c3bc0d..c82a8b9f5a 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -311,6 +311,7 @@ public: [[nodiscard]] rpl::producer wrapValue() const; [[nodiscard]] not_null wrapWidget() const; void setSection(not_null memento); + [[nodiscard]] bool hasBackButton() const; Ui::SearchFieldController *searchFieldController() const { return _searchFieldController.get(); diff --git a/Telegram/SourceFiles/info/info_wrap_widget.h b/Telegram/SourceFiles/info/info_wrap_widget.h index 815765154a..fe0c4ccd28 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.h +++ b/Telegram/SourceFiles/info/info_wrap_widget.h @@ -122,6 +122,7 @@ public: object_ptr createTopBarSurrogate(QWidget *parent); + [[nodiscard]] bool hasBackButton() const; [[nodiscard]] bool closeByOutsideClick() const; void updateGeometry( @@ -181,7 +182,6 @@ private: void highlightTopBar(); void setupShortcuts(); - [[nodiscard]] bool hasBackButton() const; [[nodiscard]] bool willHaveBackButton( const Window::SectionShow ¶ms) const;