Improved animation speed on release of swipe-on-reply with various x.

This commit is contained in:
23rd 2024-09-04 15:45:07 +03:00 committed by John Preston
parent 96b7755cde
commit 52e42f23ab

View file

@ -28,6 +28,7 @@ void SetupSwipeHandler(
Fn<SwipeHandlerFinishData(int)> generateFinishByTop, Fn<SwipeHandlerFinishData(int)> generateFinishByTop,
rpl::producer<bool> dontStart) { rpl::producer<bool> dontStart) {
constexpr auto kThresholdWidth = 50; constexpr auto kThresholdWidth = 50;
constexpr auto kMaxRatio = 1.5;
const auto threshold = style::ConvertFloatScale(kThresholdWidth); const auto threshold = style::ConvertFloatScale(kThresholdWidth);
struct State { struct State {
base::unique_qptr<QObject> filter; base::unique_qptr<QObject> filter;
@ -54,10 +55,10 @@ void SetupSwipeHandler(
}, state->lifetime); }, state->lifetime);
const auto updateRatio = [=](float64 ratio) { 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.msgBareId = state->finishByTopData.msgBareId;
state->data.translation = int( 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; state->data.cursorTop = state->cursorTop;
update(state->data); update(state->data);
}; };
@ -71,7 +72,10 @@ void SetupSwipeHandler(
}; };
const auto processEnd = [=](std::optional<QPointF> delta = {}) { const auto processEnd = [=](std::optional<QPointF> delta = {}) {
if (state->orientation == Qt::Horizontal) { 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) { if ((ratio >= 1) && state->finishByTopData.callback) {
Ui::PostponeCall( Ui::PostponeCall(
widget, widget,
@ -82,7 +86,7 @@ void SetupSwipeHandler(
updateRatio, updateRatio,
ratio, ratio,
0., 0.,
st::slideWrapDuration); std::min(1., ratio) * st::slideWrapDuration);
} }
setOrientation(std::nullopt); setOrientation(std::nullopt);
state->started = false; state->started = false;