From 52e42f23ab9ff4712cdea094df882b837a1faba0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 4 Sep 2024 15:45:07 +0300 Subject: [PATCH] Improved animation speed on release of swipe-on-reply with various x. --- Telegram/SourceFiles/history/history_view_swipe.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/history_view_swipe.cpp b/Telegram/SourceFiles/history/history_view_swipe.cpp index 64a6f811f..b028f6969 100644 --- a/Telegram/SourceFiles/history/history_view_swipe.cpp +++ b/Telegram/SourceFiles/history/history_view_swipe.cpp @@ -28,6 +28,7 @@ void SetupSwipeHandler( Fn generateFinishByTop, rpl::producer dontStart) { constexpr auto kThresholdWidth = 50; + constexpr auto kMaxRatio = 1.5; const auto threshold = style::ConvertFloatScale(kThresholdWidth); struct State { base::unique_qptr filter; @@ -54,10 +55,10 @@ void SetupSwipeHandler( }, state->lifetime); const auto updateRatio = [=](float64 ratio) { - state->data.ratio = std::clamp(ratio, 0., 1.5), + state->data.ratio = std::clamp(ratio, 0., kMaxRatio), state->data.msgBareId = state->finishByTopData.msgBareId; state->data.translation = int( - base::SafeRound(-std::clamp(ratio, 0., 1.5) * threshold)); + base::SafeRound(-std::clamp(ratio, 0., kMaxRatio) * threshold)); state->data.cursorTop = state->cursorTop; update(state->data); }; @@ -71,7 +72,10 @@ void SetupSwipeHandler( }; const auto processEnd = [=](std::optional delta = {}) { if (state->orientation == Qt::Horizontal) { - const auto ratio = delta.value_or(state->delta).x() / threshold; + const auto ratio = std::clamp( + delta.value_or(state->delta).x() / threshold, + 0., + kMaxRatio); if ((ratio >= 1) && state->finishByTopData.callback) { Ui::PostponeCall( widget, @@ -82,7 +86,7 @@ void SetupSwipeHandler( updateRatio, ratio, 0., - st::slideWrapDuration); + std::min(1., ratio) * st::slideWrapDuration); } setOrientation(std::nullopt); state->started = false;