chore: Make accessoryImageView more universal

This commit is contained in:
Marcus Kida 2022-11-15 14:07:22 +01:00
parent 533e626094
commit 3acdbcc2ce
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 15 additions and 16 deletions

View File

@ -80,7 +80,7 @@ extension SidebarViewModel {
}()
cell.item = SidebarListContentView.Item(
isActive: false,
showAccountSwitcher: item == .me,
accessoryImage: item == .me ? UIImage(systemName: "chevron.up.chevron.down") : nil,
title: item.title,
image: item.image,
activeImage: item.selectedImage,
@ -158,7 +158,6 @@ extension SidebarViewModel {
case .setting:
let item = SidebarListContentView.Item(
isActive: false,
showAccountSwitcher: false,
title: L10n.Common.Controls.Actions.settings,
image: Asset.ObjectsAndTools.gear.image.withRenderingMode(.alwaysTemplate),
activeImage: Asset.ObjectsAndTools.gear.image.withRenderingMode(.alwaysTemplate),
@ -168,7 +167,7 @@ extension SidebarViewModel {
case .compose:
let item = SidebarListContentView.Item(
isActive: false,
showAccountSwitcher: self.currentTab == .me,
accessoryImage: self.currentTab == .me ? UIImage(systemName: "chevron.up.chevron.down") : nil,
title: L10n.Common.Controls.Actions.compose,
image: Asset.ObjectsAndTools.squareAndPencil.image.withRenderingMode(.alwaysTemplate),
activeImage: Asset.ObjectsAndTools.squareAndPencil.image.withRenderingMode(.alwaysTemplate),
@ -216,7 +215,6 @@ extension SidebarViewModel {
let item = SidebarListContentView.Item(
isActive: false,
showAccountSwitcher: false,
title: L10n.Common.Controls.Actions.compose,
image: Asset.ObjectsAndTools.squareAndPencil.image.withRenderingMode(.alwaysTemplate),
activeImage: Asset.ObjectsAndTools.squareAndPencil.image.withRenderingMode(.alwaysTemplate),

View File

@ -23,7 +23,7 @@ final class SidebarListContentView: UIView, UIContentView {
button.borderColor = UIColor.label
return button
}()
private let accountToggleIndicator = UIImageView(image: UIImage(systemName: "chevron.up.chevron.down"))
private let accessoryImageView = UIImageView(image: nil)
private var currentConfiguration: ContentConfiguration!
var configuration: UIContentConfiguration {
@ -62,8 +62,8 @@ extension SidebarListContentView {
imageView.heightAnchor.constraint(equalToConstant: 40).priority(.required - 1),
])
accountToggleIndicator.translatesAutoresizingMaskIntoConstraints = false
addSubview(accountToggleIndicator)
accessoryImageView.translatesAutoresizingMaskIntoConstraints = false
addSubview(accessoryImageView)
avatarButton.translatesAutoresizingMaskIntoConstraints = false
addSubview(avatarButton)
@ -72,10 +72,10 @@ extension SidebarListContentView {
avatarButton.centerYAnchor.constraint(equalTo: imageView.centerYAnchor),
avatarButton.widthAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: 1.0).priority(.required - 2),
avatarButton.heightAnchor.constraint(equalTo: imageView.heightAnchor, multiplier: 1.0).priority(.required - 2),
accountToggleIndicator.widthAnchor.constraint(equalToConstant: 12),
accountToggleIndicator.heightAnchor.constraint(equalToConstant: 22),
accountToggleIndicator.leadingAnchor.constraint(equalTo: avatarButton.trailingAnchor, constant: 4),
accountToggleIndicator.centerYAnchor.constraint(equalTo: avatarButton.centerYAnchor)
accessoryImageView.widthAnchor.constraint(equalToConstant: 12),
accessoryImageView.heightAnchor.constraint(equalToConstant: 22),
accessoryImageView.leadingAnchor.constraint(equalTo: avatarButton.trailingAnchor, constant: 4),
accessoryImageView.centerYAnchor.constraint(equalTo: avatarButton.centerYAnchor)
])
avatarButton.setContentHuggingPriority(.defaultLow - 10, for: .vertical)
avatarButton.setContentHuggingPriority(.defaultLow - 10, for: .horizontal)
@ -104,8 +104,9 @@ extension SidebarListContentView {
imageView.isHidden = item.imageURL != nil
avatarButton.isHidden = item.imageURL == nil
imageView.image = item.isActive ? item.activeImage.withRenderingMode(.alwaysTemplate) : item.image.withRenderingMode(.alwaysTemplate)
accountToggleIndicator.isHidden = !item.showAccountSwitcher
accountToggleIndicator.tintColor = item.isActive ? .label : .secondaryLabel
accessoryImageView.image = item.accessoryImage
accessoryImageView.isHidden = item.accessoryImage == nil
accessoryImageView.tintColor = item.isActive ? .label : .secondaryLabel
avatarButton.avatarImageView.setImage(
url: item.imageURL,
placeholder: avatarButton.avatarImageView.image ?? .placeholder(color: .systemFill), // reuse to avoid blink
@ -122,7 +123,7 @@ extension SidebarListContentView {
var isSelected: Bool = false
var isHighlighted: Bool = false
var isActive: Bool
var showAccountSwitcher: Bool
var accessoryImage: UIImage? = nil
// model
let title: String
@ -135,7 +136,7 @@ extension SidebarListContentView {
return lhs.isSelected == rhs.isSelected
&& lhs.isHighlighted == rhs.isHighlighted
&& lhs.isActive == rhs.isActive
&& lhs.showAccountSwitcher == rhs.showAccountSwitcher
&& lhs.accessoryImage == rhs.accessoryImage
&& lhs.title == rhs.title
&& lhs.image == rhs.image
&& lhs.activeImage == rhs.activeImage
@ -146,7 +147,7 @@ extension SidebarListContentView {
hasher.combine(isSelected)
hasher.combine(isHighlighted)
hasher.combine(isActive)
hasher.combine(showAccountSwitcher)
hasher.combine(accessoryImage)
hasher.combine(title)
hasher.combine(image)
hasher.combine(activeImage)