chore: DRY setting up colors from theme

This commit is contained in:
Peter Minarik 2022-12-25 16:56:46 +01:00
parent 530d69a78c
commit c1f19d1f27
No known key found for this signature in database
GPG Key ID: 7CBCECB768860C82
1 changed files with 10 additions and 6 deletions

View File

@ -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)