Added ability to provide custom swipe handler to Info::ContentWidget.

This commit is contained in:
23rd 2025-03-24 21:42:35 +03:00
parent f734c0475b
commit 0d085d500f
4 changed files with 29 additions and 0 deletions

View file

@ -410,7 +410,19 @@ not_null<Ui::ScrollArea*> ContentWidget::scroll() const {
return _scroll.data();
}
void ContentWidget::replaceSwipeHandler(
Ui::Controls::SwipeHandlerArgs *incompleteArgs) {
_swipeHandlerLifetime.destroy();
auto args = std::move(*incompleteArgs);
args.widget = _innerWrap;
args.scroll = _scroll.data();
args.onLifetime = &_swipeHandlerLifetime;
Ui::Controls::SetupSwipeHandler(std::move(args));
}
void ContentWidget::setupSwipeHandler(not_null<Ui::RpWidget*> widget) {
_swipeHandlerLifetime.destroy();
auto update = [=](Ui::Controls::SwipeContextData data) {
if (data.translation > 0) {
if (!_swipeBackData.callback) {
@ -446,6 +458,7 @@ void ContentWidget::setupSwipeHandler(not_null<Ui::RpWidget*> widget) {
.scroll = _scroll.data(),
.update = std::move(update),
.init = std::move(init),
.onLifetime = &_swipeHandlerLifetime,
});
}

View file

@ -24,6 +24,9 @@ enum class SharedMediaType : signed char;
} // namespace Storage
namespace Ui {
namespace Controls {
struct SwipeHandlerArgs;
} // namespace Controls
class RoundRect;
class ScrollArea;
class InputField;
@ -135,6 +138,8 @@ public:
[[nodiscard]] virtual auto desiredBottomShadowVisibility()
-> rpl::producer<bool>;
void replaceSwipeHandler(Ui::Controls::SwipeHandlerArgs *incompleteArgs);
protected:
template <typename Widget>
Widget *setInnerWidget(object_ptr<Widget> inner) {
@ -196,6 +201,7 @@ private:
style::margins _paintPadding;
Ui::Controls::SwipeBackResult _swipeBackData;
rpl::lifetime _swipeHandlerLifetime;
};

View file

@ -1059,6 +1059,11 @@ bool WrapWidget::willHaveBackButton(
return (wrap() == Wrap::Narrow) || willHaveStack;
}
void WrapWidget::replaceSwipeHandler(
Ui::Controls::SwipeHandlerArgs *incompleteArgs) {
_content->replaceSwipeHandler(std::move(incompleteArgs));
}
WrapWidget::~WrapWidget() = default;
} // namespace Info

View file

@ -15,6 +15,9 @@ enum class SharedMediaType : signed char;
} // namespace Storage
namespace Ui {
namespace Controls {
struct SwipeHandlerArgs;
} // namespace Controls
class FadeShadow;
class PlainShadow;
class PopupMenu;
@ -140,6 +143,8 @@ public:
return _removeRequests.events();
}
void replaceSwipeHandler(Ui::Controls::SwipeHandlerArgs *incompleteArgs);
~WrapWidget();
protected: