Allow playing single lottie icon repeatedly or once.

This commit is contained in:
John Preston 2022-05-04 11:39:53 +04:00
parent 3ff4bf77e7
commit f2b89445ae
7 changed files with 22 additions and 23 deletions

View File

@ -510,7 +510,7 @@ void ChangePhone::setupContent() {
}
void ChangePhone::showFinished() {
_animate();
_animate(anim::repeat::loop);
}
} // namespace Settings

View File

@ -36,7 +36,7 @@ private:
void setupContent();
const not_null<Window::SessionController*> _controller;
Fn<void()> _animate;
Fn<void(anim::repeat)> _animate;
};

View File

@ -171,13 +171,12 @@ void Blocked::setupContent() {
st::changePhoneIconSize,
},
},
st::blockedUsersListIconPadding,
true);
st::blockedUsersListIconPadding);
content->add(std::move(icon.widget));
_showFinished.events(
) | rpl::start_with_next([animate = std::move(icon.animate)] {
animate();
animate(anim::repeat::once);
}, content->lifetime());
content->add(

View File

@ -249,8 +249,7 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
LottieIcon CreateLottieIcon(
not_null<QWidget*> parent,
Lottie::IconDescriptor &&descriptor,
style::margins padding,
bool playOnce) {
style::margins padding) {
auto object = object_ptr<Ui::RpWidget>(parent);
const auto raw = object.data();
@ -263,23 +262,22 @@ LottieIcon CreateLottieIcon(
const auto icon = owned.get();
raw->lifetime().add([kept = std::move(owned)]{});
const auto animationRequired = raw->lifetime().make_state<bool>(true);
const auto looped = raw->lifetime().make_state<bool>(true);
const auto animate = [=] {
if (playOnce) {
if (!base::take(*animationRequired)) {
return;
}
}
const auto start = [=] {
icon->animate([=] { raw->update(); }, 0, icon->framesCount() - 1);
};
const auto animate = [=](anim::repeat repeat) {
*looped = (repeat == anim::repeat::loop);
start();
};
raw->paintRequest(
) | rpl::start_with_next([=] {
auto p = QPainter(raw);
const auto left = (raw->width() - width) / 2;
icon->paint(p, left, padding.top());
if (!icon->animating() && icon->frameIndex() > 0) {
animate();
if (!icon->animating() && icon->frameIndex() > 0 && *looped) {
start();
}
}, raw->lifetime());

View File

@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/object_ptr.h"
#include "settings/settings_type.h"
namespace anim {
enum class repeat : uchar;
} // namespace anim
namespace Main {
class Session;
} // namespace Main
@ -180,13 +184,12 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
struct LottieIcon {
object_ptr<Ui::RpWidget> widget;
Fn<void()> animate;
Fn<void(anim::repeat repeat)> animate;
};
[[nodiscard]] LottieIcon CreateLottieIcon(
not_null<QWidget*> parent,
Lottie::IconDescriptor &&descriptor,
style::margins padding = {},
bool playOnce = false);
style::margins padding = {});
void FillMenu(
not_null<Window::SessionController*> controller,

View File

@ -613,11 +613,10 @@ QPointer<Ui::RpWidget> Folders::createPinnedToTop(not_null<QWidget*> parent) {
st::settingsFilterIconSize,
},
},
st::settingsFilterIconPadding,
true);
st::settingsFilterIconPadding);
_showFinished.events(
) | rpl::start_with_next([animate = std::move(icon.animate)] {
animate();
animate(anim::repeat::once);
}, verticalLayout->lifetime());
verticalLayout->add(std::move(icon.widget));

@ -1 +1 @@
Subproject commit 9d07d6a476f057c55af9392804c3e8b6246c637c
Subproject commit 9b6e11db62810626a56431cdc8eeb771817f6560