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

View file

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

View file

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

View file

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

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