From c1f19d1f27c8af4e285148ccbd0c0ca82eee82ce Mon Sep 17 00:00:00 2001 From: Peter Minarik Date: Sun, 25 Dec 2022 16:56:46 +0100 Subject: [PATCH] chore: DRY setting up colors from theme --- .../Profile/Header/View/ProfileHeaderView.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift index ccc3dbe9f..c3ae089e7 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift @@ -242,14 +242,13 @@ final class ProfileHeaderView: UIView { extension ProfileHeaderView { private func _init() { - backgroundColor = ThemeService.shared.currentTheme.value.systemBackgroundColor - avatarButton.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor - ThemeService.shared.currentTheme + let currentTheme = ThemeService.shared.currentTheme + setColors(from: currentTheme.value) + + currentTheme .receive(on: DispatchQueue.main) .sink { [weak self] theme in - guard let self = self else { return } - self.backgroundColor = theme.systemBackgroundColor - self.avatarButton.backgroundColor = theme.secondarySystemBackgroundColor + self?.setColors(from: theme) } .store(in: &_disposeBag) @@ -455,6 +454,11 @@ extension ProfileHeaderView { updateLayoutMargins() } + + private func setColors(from theme: Theme) { + backgroundColor = theme.systemBackgroundColor + avatarButton.backgroundColor = theme.secondarySystemBackgroundColor + } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection)