Stop timer for infinite radial animation when animations are disabled

This commit is contained in:
Ilya Fedin 2024-01-13 04:15:42 +04:00 committed by John Preston
parent 564e354c1d
commit cb1a041ca3
2 changed files with 21 additions and 5 deletions

View file

@ -112,13 +112,25 @@ RadialState RadialAnimation::computeState() const {
return { _opacity, from, length };
}
void InfiniteRadialAnimation::init() {
anim::Disables() | rpl::filter([=] {
return animating();
}) | rpl::start_with_next([=](bool disabled) {
if (!disabled && !_animation.animating()) {
_animation.start();
} else if (disabled && _animation.animating()) {
_animation.stop();
}
}, _lifetime);
}
void InfiniteRadialAnimation::start(crl::time skip) {
if (!animating()) {
const auto now = crl::now();
if (_workFinished <= now && (_workFinished || !_workStarted)) {
_workStarted = std::max(now + _st.sineDuration - skip, crl::time(1));
_workFinished = 0;
}
if (!_animation.animating()) {
if (!anim::Disabled() && !_animation.animating()) {
_animation.start();
}
}
@ -213,7 +225,7 @@ RadialState InfiniteRadialAnimation::computeState() {
const auto now = crl::now();
const auto linear = kFullArcLength
- int(((now * kFullArcLength) / _st.linearPeriod) % kFullArcLength);
if (!_workStarted || (_workFinished && _workFinished <= now)) {
if (!animating()) {
const auto shown = 0.;
_animation.stop();
return {

View file

@ -73,7 +73,7 @@ public:
const style::InfiniteRadialAnimation &st);
[[nodiscard]] bool animating() const {
return _animation.animating();
return _workStarted && (!_workFinished || _workFinished > crl::now());
}
void start(crl::time skip = 0);
@ -101,10 +101,13 @@ public:
[[nodiscard]] RadialState computeState();
private:
void init();
const style::InfiniteRadialAnimation &_st;
crl::time _workStarted = 0;
crl::time _workFinished = 0;
Ui::Animations::Basic _animation;
rpl::lifetime _lifetime;
};
@ -114,6 +117,7 @@ inline InfiniteRadialAnimation::InfiniteRadialAnimation(
const style::InfiniteRadialAnimation &st)
: _st(st)
, _animation(std::forward<Callback>(callback)) {
init();
}
} // namespace Ui