From 1da57c5848448b433948a026f8a887942be00dd9 Mon Sep 17 00:00:00 2001 From: Nikolai Nechaev Date: Tue, 31 Dec 2024 20:36:01 +0300 Subject: [PATCH] Fix `Ui::Animations::Simple`'s `.start()` and `.change()` methods Unlike the `.change()` method, which configures a running animation to go to a different state, the `.start()` method should first set the initial opacity value, then animate. It is fixed by making sure the private `.prepare()` method always sets `from`, rather than ignoring it when the animation is already running. --- ui/effects/animations.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/effects/animations.h b/ui/effects/animations.h index a918cfc4..c4cbb356 100644 --- a/ui/effects/animations.h +++ b/ui/effects/animations.h @@ -381,16 +381,19 @@ inline void Simple::change( anim::transition transition) { Expects(_data != nullptr); - prepare(0. /* ignored */, duration); + prepare(_data->value /* keep the old value */, duration); startPrepared(to, duration, transition); } inline void Simple::prepare(float64 from, crl::time duration) { const auto isLong = (duration > kLongAnimationDuration); - if (!_data) { + if (_data) { + _data->value = from; + if (!isLong) { + _data->tracker.restart(); + } + } else { _data = std::make_unique(from); - } else if (!isLong) { - _data->tracker.restart(); } if (isLong) { _data->tracker.release();