mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-08 12:43:52 +00:00
Added swipe interceptor to info content widget.
This commit is contained in:
@@ -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<Ui::RpWidget*> 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<Ui::RpWidget*> widget) {
|
||||
st::historyForwardChooseBg->c,
|
||||
st::historyForwardChooseFg->c,
|
||||
};
|
||||
});
|
||||
},
|
||||
data.translation < 0);
|
||||
}
|
||||
_swipeBackData.callback(data);
|
||||
return;
|
||||
@@ -543,6 +548,22 @@ void ContentWidget::setupSwipeHandler(not_null<Ui::RpWidget*> 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();
|
||||
}
|
||||
|
||||
@@ -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<Ui::Controls::SwipeHandlerFinishData(
|
||||
Ui::Controls::SwipeHandlerInitData)>;
|
||||
void setSwipeInterceptor(SwipeInterceptor interceptor);
|
||||
|
||||
protected:
|
||||
template <typename Widget>
|
||||
Widget *setInnerWidget(object_ptr<Widget> inner) {
|
||||
@@ -247,6 +252,7 @@ private:
|
||||
style::margins _paintPadding;
|
||||
|
||||
Ui::Controls::SwipeBackResult _swipeBackData;
|
||||
SwipeInterceptor _swipeInterceptor;
|
||||
rpl::lifetime _swipeHandlerLifetime;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user