From 3ff4bf77e7aebf7954e7289b07e7cb1153120fe0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 4 May 2022 00:02:52 +0300 Subject: [PATCH] Removed repeated animation from some settings lottie icons. --- .../settings/settings_blocked_peers.cpp | 16 ++++++++++------ .../SourceFiles/settings/settings_common.cpp | 9 ++++++++- Telegram/SourceFiles/settings/settings_common.h | 3 ++- .../SourceFiles/settings/settings_folders.cpp | 16 ++++++++++------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/settings/settings_blocked_peers.cpp b/Telegram/SourceFiles/settings/settings_blocked_peers.cpp index cee383e3ee..64b01477b2 100644 --- a/Telegram/SourceFiles/settings/settings_blocked_peers.cpp +++ b/Telegram/SourceFiles/settings/settings_blocked_peers.cpp @@ -162,13 +162,17 @@ void Blocked::setupContent() { { const auto content = emptyWrap->entity(); - auto icon = CreateLottieIcon(content, { - .name = u"blocked_peers_empty"_q, - .sizeOverride = { - st::changePhoneIconSize, - st::changePhoneIconSize, + auto icon = CreateLottieIcon( + content, + { + .name = u"blocked_peers_empty"_q, + .sizeOverride = { + st::changePhoneIconSize, + st::changePhoneIconSize, + }, }, - }, st::blockedUsersListIconPadding); + st::blockedUsersListIconPadding, + true); content->add(std::move(icon.widget)); _showFinished.events( diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index 9c19673229..c4d7650733 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -249,7 +249,8 @@ not_null AddSubsectionTitle( LottieIcon CreateLottieIcon( not_null parent, Lottie::IconDescriptor &&descriptor, - style::margins padding) { + style::margins padding, + bool playOnce) { auto object = object_ptr(parent); const auto raw = object.data(); @@ -262,8 +263,14 @@ LottieIcon CreateLottieIcon( const auto icon = owned.get(); raw->lifetime().add([kept = std::move(owned)]{}); + const auto animationRequired = raw->lifetime().make_state(true); const auto animate = [=] { + if (playOnce) { + if (!base::take(*animationRequired)) { + return; + } + } icon->animate([=] { raw->update(); }, 0, icon->framesCount() - 1); }; raw->paintRequest( diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index 5118350375..5bf9e064be 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -185,7 +185,8 @@ struct LottieIcon { [[nodiscard]] LottieIcon CreateLottieIcon( not_null parent, Lottie::IconDescriptor &&descriptor, - style::margins padding = {}); + style::margins padding = {}, + bool playOnce = false); void FillMenu( not_null controller, diff --git a/Telegram/SourceFiles/settings/settings_folders.cpp b/Telegram/SourceFiles/settings/settings_folders.cpp index c3e4f1819b..efeb5032db 100644 --- a/Telegram/SourceFiles/settings/settings_folders.cpp +++ b/Telegram/SourceFiles/settings/settings_folders.cpp @@ -604,13 +604,17 @@ QPointer Folders::createPinnedToTop(not_null parent) { const auto divider = Ui::CreateChild(parent.get()); const auto verticalLayout = Ui::CreateChild(divider); - auto icon = CreateLottieIcon(this, { - .name = u"filters"_q, - .sizeOverride = { - st::settingsFilterIconSize, - st::settingsFilterIconSize, + auto icon = CreateLottieIcon( + this, + { + .name = u"filters"_q, + .sizeOverride = { + st::settingsFilterIconSize, + st::settingsFilterIconSize, + }, }, - }, st::settingsFilterIconPadding); + st::settingsFilterIconPadding, + true); _showFinished.events( ) | rpl::start_with_next([animate = std::move(icon.animate)] { animate();