diff --git a/Telegram/SourceFiles/ui/widgets/vertical_drum_picker.cpp b/Telegram/SourceFiles/ui/widgets/vertical_drum_picker.cpp index 9e546e004..d0cc71ca3 100644 --- a/Telegram/SourceFiles/ui/widgets/vertical_drum_picker.cpp +++ b/Telegram/SourceFiles/ui/widgets/vertical_drum_picker.cpp @@ -11,6 +11,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_basic.h" namespace Ui { +namespace { + +constexpr auto kAlmostIndex = float64(.99); + +} // namespace PickerAnimation::PickerAnimation() = default; @@ -26,6 +31,23 @@ void PickerAnimation::jumpToOffset(int offset) { value); _updates.fire(_result.current - was); }; + if (anim::Disabled()) { + auto value = float64(0.); + const auto diff = _result.to - _result.from; + const auto step = std::min( + kAlmostIndex, + 1. / (std::max(1. - kAlmostIndex, std::abs(diff) + 1))); + while (true) { + value += step; + if (value >= 1.) { + callback(1.); + break; + } else { + callback(value); + } + } + return; + } _animation.start( std::move(callback), 0., @@ -94,20 +116,14 @@ VerticalDrumPicker::VerticalDrumPicker( }, lifetime()); _animation.updates( - ) | rpl::distinct_until_changed( ) | rpl::start_with_next([=](PickerAnimation::Shift shift) { increaseShift(shift); - if (anim::Disabled()) { - animationDataFromIndex(); - _animation.jumpToOffset(0); - } }, lifetime()); } void VerticalDrumPicker::increaseShift(float64 by) { { // Guard input. - constexpr auto kAlmostIndex = .99; if (by >= 1.) { by = kAlmostIndex; } else if (by <= -1.) {