Add elastic overscroll to swipe-to-reply.

This commit is contained in:
John Preston 2024-09-06 20:00:00 +04:00
parent 1f4516028c
commit 5e32602f4a
5 changed files with 24 additions and 13 deletions

View file

@ -671,6 +671,8 @@ PeerShortInfoBox::PeerShortInfoBox(
) | rpl::start_with_next([=] {
_cover.setScrollTop(_scroll->scrollTop());
}, _cover.lifetime());
setCustomCornersFilling(RectPart::FullTop);
}
PeerShortInfoBox::~PeerShortInfoBox() = default;
@ -795,10 +797,6 @@ void PeerShortInfoBox::prepareRows() {
tr::lng_mediaview_copy(tr::now));
}
RectParts PeerShortInfoBox::customCornersFilling() {
return RectPart::FullTop;
}
void PeerShortInfoBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);

View file

@ -162,7 +162,6 @@ public:
private:
void prepare() override;
void prepareRows();
RectParts customCornersFilling() override;
void resizeEvent(QResizeEvent *e) override;

View file

@ -20,6 +20,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication>
namespace HistoryView {
namespace {
constexpr auto kSwipeSlow = 0.2;
} // namespace
void SetupSwipeHandler(
not_null<Ui::RpWidget*> widget,
@ -63,10 +68,16 @@ void SetupSwipeHandler(
}, state->lifetime);
const auto updateRatio = [=](float64 ratio) {
state->data.ratio = std::clamp(ratio, 0., kMaxRatio),
ratio = std::max(ratio, 0.);
state->data.ratio = ratio;
const auto overscrollRatio = std::max(ratio - 1., 0.);
const auto translation = int(
base::SafeRound(-std::min(ratio, 1.) * threshold)
) + Ui::OverscrollFromAccumulated(int(
base::SafeRound(-overscrollRatio * threshold)
));
state->data.msgBareId = state->finishByTopData.msgBareId;
state->data.translation = int(
base::SafeRound(-std::clamp(ratio, 0., kMaxRatio) * threshold));
state->data.translation = translation;
state->data.cursorTop = state->cursorTop;
update(state->data);
};
@ -248,10 +259,11 @@ void SetupSwipeHandler(
processEnd();
} else {
const auto invert = (w->inverted() ? -1 : 1);
const auto delta = Ui::ScrollDeltaF(w) * invert;
updateWith({
.globalCursor = w->globalPosition().toPoint(),
.position = QPointF(),
.delta = state->delta + Ui::ScrollDelta(w) * invert,
.delta = state->delta + delta * kSwipeSlow,
.touch = false,
});
}

View file

@ -1512,10 +1512,12 @@ void Message::draw(Painter &p, const PaintContext &context) const {
+ ((g.height() < size * kMaxHeightRatio)
? rightActionSize().value_or(QSize()).width()
: 0);
const auto shift = std::min(
(size * kShiftRatio * context.gestureHorizontal.ratio),
-1. * context.gestureHorizontal.translation
) + (st::historySwipeIconSkip * ratio * (isLeftSize ? .7 : 1.));
const auto rect = QRectF(
outerWidth
- (size * kShiftRatio * context.gestureHorizontal.ratio)
- (st::historySwipeIconSkip * ratio * (isLeftSize ? .7 : 1.)),
outerWidth - shift,
g.y() + (g.height() - size) / 2,
size,
size);

@ -1 +1 @@
Subproject commit 9965046aac159fab07bbe99d27692d76d1b86312
Subproject commit 9ca74272a0ec33bac83c5b61a73d523902eb96cd