From 1cbc38525395fd9fc51d9ba4e80281d102dd5a1e Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 4 Nov 2021 15:21:12 +0800 Subject: [PATCH] fix: sidebar avatar button color not update when toggle device appearance issue --- .../Root/Sidebar/View/SidebarListContentView.swift | 2 +- Mastodon/Scene/Share/View/Button/AvatarButton.swift | 12 ++++++++++++ .../Scene/Share/View/Button/CircleAvatarButton.swift | 11 +++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Mastodon/Scene/Root/Sidebar/View/SidebarListContentView.swift b/Mastodon/Scene/Root/Sidebar/View/SidebarListContentView.swift index d85d3a8b..d6ae40e1 100644 --- a/Mastodon/Scene/Root/Sidebar/View/SidebarListContentView.swift +++ b/Mastodon/Scene/Root/Sidebar/View/SidebarListContentView.swift @@ -18,7 +18,7 @@ final class SidebarListContentView: UIView, UIContentView { let avatarButton: CircleAvatarButton = { let button = CircleAvatarButton() button.borderWidth = 2 - button.borderColor = UIColor.label.cgColor + button.borderColor = UIColor.label return button }() diff --git a/Mastodon/Scene/Share/View/Button/AvatarButton.swift b/Mastodon/Scene/Share/View/Button/AvatarButton.swift index 9bc87a05..6249ea37 100644 --- a/Mastodon/Scene/Share/View/Button/AvatarButton.swift +++ b/Mastodon/Scene/Share/View/Button/AvatarButton.swift @@ -38,6 +38,18 @@ class AvatarButton: UIControl { avatarImageView.bottomAnchor.constraint(equalTo: bottomAnchor), ]) } + + override func layoutSubviews() { + super.layoutSubviews() + + updateAppearance() + } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + updateAppearance() + } func updateAppearance() { avatarImageView.alpha = primaryActionState.contains(.highlighted) ? 0.6 : 1.0 diff --git a/Mastodon/Scene/Share/View/Button/CircleAvatarButton.swift b/Mastodon/Scene/Share/View/Button/CircleAvatarButton.swift index 0bc2aeef..74591dda 100644 --- a/Mastodon/Scene/Share/View/Button/CircleAvatarButton.swift +++ b/Mastodon/Scene/Share/View/Button/CircleAvatarButton.swift @@ -9,15 +9,18 @@ import UIKit final class CircleAvatarButton: AvatarButton { - var borderColor: CGColor = UIColor.systemFill.cgColor + @Published var needsHighlighted = false + + var borderColor: UIColor = UIColor.systemFill var borderWidth: CGFloat = 1.0 - override func layoutSubviews() { - super.layoutSubviews() + override func updateAppearance() { + super.updateAppearance() layer.masksToBounds = true layer.cornerRadius = frame.width * 0.5 - layer.borderColor = borderColor + layer.borderColor = borderColor.cgColor layer.borderWidth = borderWidth } + }