Move the author-button into its own class (IOS-284)
and add avatar-image
This commit is contained in:
parent
c61d3d7cb2
commit
52ba086f94
|
@ -0,0 +1,52 @@
|
|||
import UIKit
|
||||
import MastodonAsset
|
||||
import MastodonSDK
|
||||
|
||||
class StatusCardAuthorControl: UIControl {
|
||||
let authorLabel: UILabel
|
||||
let avatarImage: AvatarImageView
|
||||
private let contentStackView: UIStackView
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
authorLabel = UILabel()
|
||||
authorLabel.textAlignment = .center
|
||||
authorLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 16, weight: .bold))
|
||||
avatarImage = AvatarImageView()
|
||||
avatarImage.translatesAutoresizingMaskIntoConstraints = false
|
||||
avatarImage.configure(cornerConfiguration: AvatarImageView.CornerConfiguration(corner: .fixed(radius: 4)))
|
||||
contentStackView = UIStackView(arrangedSubviews: [avatarImage, authorLabel])
|
||||
contentStackView.spacing = 6
|
||||
contentStackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentStackView.layoutMargins = UIEdgeInsets(horizontal: 6, vertical: 8)
|
||||
contentStackView.isUserInteractionEnabled = true
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
addSubview(contentStackView)
|
||||
setupConstraints()
|
||||
backgroundColor = Asset.Colors.Button.userFollowing.color
|
||||
layer.cornerRadius = 10
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
private func setupConstraints() {
|
||||
let constraints = [
|
||||
contentStackView.topAnchor.constraint(equalTo: topAnchor, constant: 6),
|
||||
contentStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 6),
|
||||
trailingAnchor.constraint(equalTo: contentStackView.trailingAnchor, constant: 6),
|
||||
bottomAnchor.constraint(equalTo: contentStackView.bottomAnchor, constant: 6),
|
||||
|
||||
avatarImage.widthAnchor.constraint(equalToConstant: 16),
|
||||
avatarImage.widthAnchor.constraint(equalTo: avatarImage.heightAnchor),
|
||||
authorLabel.heightAnchor.constraint(greaterThanOrEqualTo: avatarImage.heightAnchor)
|
||||
]
|
||||
|
||||
NSLayoutConstraint.activate(constraints)
|
||||
}
|
||||
|
||||
public func configure(with account: Mastodon.Entity.Account) {
|
||||
authorLabel.text = account.displayNameWithFallback
|
||||
avatarImage.configure(with: account.avatarImageURL())
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public final class StatusCardControl: UIControl {
|
|||
private let mastodonLogoImageView: UIImageView
|
||||
private let byLabel: UILabel
|
||||
private let authorLabel: UILabel
|
||||
private let authorAccountButton: UIButton
|
||||
private let authorAccountButton: StatusCardAuthorControl
|
||||
private let authorStackView: UIStackView
|
||||
|
||||
private static let cardContentPool = WKProcessPool()
|
||||
|
@ -90,7 +90,7 @@ public final class StatusCardControl: UIControl {
|
|||
mastodonLogoImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
byLabel = UILabel()
|
||||
byLabel.text = "by"
|
||||
byLabel.text = "By"
|
||||
byLabel.numberOfLines = 1
|
||||
|
||||
authorLabel = UILabel()
|
||||
|
@ -100,15 +100,10 @@ public final class StatusCardControl: UIControl {
|
|||
publisherLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .regular))
|
||||
publisherLabel.textColor = .secondaryLabel
|
||||
|
||||
var buttonConfiguration = UIButton.Configuration.filled()
|
||||
buttonConfiguration.background.cornerRadius = 10
|
||||
buttonConfiguration.background.backgroundColor = Asset.Colors.Button.userFollowing.color
|
||||
buttonConfiguration.baseForegroundColor = Asset.Colors.Brand.blurple.color
|
||||
|
||||
authorAccountButton = UIButton(configuration: buttonConfiguration)
|
||||
authorAccountButton = StatusCardAuthorControl()
|
||||
|
||||
authorStackView = UIStackView(arrangedSubviews: [mastodonLogoImageView, byLabel, authorLabel, authorAccountButton, UIView()])
|
||||
authorStackView.alignment = .firstBaseline
|
||||
authorStackView.alignment = .center
|
||||
authorStackView.layoutMargins = .init(top: 10, left: 10, bottom: 10, right: 10)
|
||||
authorStackView.isLayoutMarginsRelativeArrangement = true
|
||||
authorStackView.spacing = 8
|
||||
|
@ -163,7 +158,6 @@ public final class StatusCardControl: UIControl {
|
|||
containerStackView.addArrangedSubview(headerContentStackView)
|
||||
containerStackView.addArrangedSubview(authorDivider)
|
||||
containerStackView.addArrangedSubview(authorStackView)
|
||||
containerStackView.setCustomSpacing(5, after: authorDivider)
|
||||
containerStackView.distribution = .fill
|
||||
|
||||
addSubview(containerStackView)
|
||||
|
@ -218,7 +212,7 @@ public final class StatusCardControl: UIControl {
|
|||
|
||||
if let author = card.authors?.first, let account = author.account {
|
||||
// , , author.url?.isEmpty == false
|
||||
authorAccountButton.configuration?.title = author.name
|
||||
authorAccountButton.configure(with: account)
|
||||
authorAccountButton.isHidden = false
|
||||
authorLabel.isHidden = true
|
||||
byLabel.isHidden = false
|
||||
|
|
Loading…
Reference in New Issue