From a566babe3a9b8ce88157ec02d70a9c52dfc93094 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 3 Feb 2021 17:50:25 -0800 Subject: [PATCH] Animate avatars by default --- .../ServiceLayer/Utilities/AppPreferences.swift | 2 +- .../ViewModels/View Models/AccountViewModel.swift | 2 +- Views/UIKit/AccountHeaderView.swift | 4 +++- Views/UIKit/CompositionView.swift | 11 ++++++++--- Views/UIKit/SecondaryNavigationTitleView.swift | 8 ++++++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift b/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift index 02b8a84..42a7eae 100644 --- a/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift +++ b/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift @@ -70,7 +70,7 @@ public extension AppPreferences { return value } - return .profiles + return .everywhere } set { self[.animateAvatars] = newValue.rawValue } } diff --git a/ViewModels/Sources/ViewModels/View Models/AccountViewModel.swift b/ViewModels/Sources/ViewModels/View Models/AccountViewModel.swift index 03f32e0..7824f6b 100644 --- a/ViewModels/Sources/ViewModels/View Models/AccountViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/AccountViewModel.swift @@ -64,7 +64,7 @@ public extension AccountViewModel { func avatarURL(profile: Bool = false) -> URL { if !identityContext.appPreferences.shouldReduceMotion, (identityContext.appPreferences.animateAvatars == .everywhere - || identityContext.appPreferences.animateAvatars == .profiles && profile) { + || (identityContext.appPreferences.animateAvatars == .profiles && profile)) { return accountService.account.avatar } else { return accountService.account.avatarStatic diff --git a/Views/UIKit/AccountHeaderView.swift b/Views/UIKit/AccountHeaderView.swift index a88b43a..a09502d 100644 --- a/Views/UIKit/AccountHeaderView.swift +++ b/Views/UIKit/AccountHeaderView.swift @@ -4,12 +4,13 @@ import Kingfisher import UIKit import ViewModels +// swiftlint:disable file_length final class AccountHeaderView: UIView { let headerImageBackgroundView = UIView() let headerImageView = AnimatedImageView() let headerButton = UIButton() let avatarBackgroundView = UIView() - let avatarImageView = UIImageView() + let avatarImageView = AnimatedImageView() let avatarButton = UIButton() let relationshipButtonsStackView = UIStackView() let followButton = UIButton(type: .system) @@ -405,3 +406,4 @@ private extension AccountHeaderView { ]) } } +// swiftlint:enable file_length diff --git a/Views/UIKit/CompositionView.swift b/Views/UIKit/CompositionView.swift index 2de2eb7..d9d1323 100644 --- a/Views/UIKit/CompositionView.swift +++ b/Views/UIKit/CompositionView.swift @@ -187,12 +187,17 @@ private extension CompositionView { } .store(in: &cancellables) - parentViewModel.$identityContext.map(\.identity) + parentViewModel.$identityContext .sink { [weak self] in guard let self = self else { return } - self.avatarImageView.kf.setImage(with: $0.image) - self.changeIdentityButton.accessibilityLabel = $0.handle + let avatarURL = $0.appPreferences.animateAvatars == .everywhere + && !$0.appPreferences.shouldReduceMotion + ? $0.identity.account?.avatar + : $0.identity.account?.avatarStatic + + self.avatarImageView.kf.setImage(with: avatarURL) + self.changeIdentityButton.accessibilityLabel = $0.identity.handle self.changeIdentityButton.accessibilityHint = NSLocalizedString("compose.change-identity-button.accessibility-hint", comment: "") } diff --git a/Views/UIKit/SecondaryNavigationTitleView.swift b/Views/UIKit/SecondaryNavigationTitleView.swift index 118e9cc..511d843 100644 --- a/Views/UIKit/SecondaryNavigationTitleView.swift +++ b/Views/UIKit/SecondaryNavigationTitleView.swift @@ -65,8 +65,12 @@ private extension SecondaryNavigationTitleView { } func applyViewModel() { - avatarImageView.kf.setImage(with: viewModel.identityContext.identity.image) - avatarImageView.autoPlayAnimatedImage = viewModel.identityContext.appPreferences.animateAvatars == .everywhere + let avatarURL = viewModel.identityContext.appPreferences.animateAvatars == .everywhere + && !viewModel.identityContext.appPreferences.shouldReduceMotion + ? viewModel.identityContext.identity.account?.avatar + : viewModel.identityContext.identity.account?.avatarStatic + + avatarImageView.kf.setImage(with: avatarURL) if let displayName = viewModel.identityContext.identity.account?.displayName, !displayName.isEmpty {