From 298886d3f576a0b8002d0ce1f52524cbab4eef7f Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 21 May 2024 17:43:53 +0200 Subject: [PATCH] Set placeholder-color for AvatarButton (IOS-238) --- .../Cell/AccountListTableViewCell.swift | 2 +- .../MastodonUI/View/Button/AvatarButton.swift | 18 ++++++------------ .../View/Button/CircleAvatarButton.swift | 6 ++++++ .../View/Content/StatusView+ViewModel.swift | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift b/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift index 53bed876a..322b8e796 100644 --- a/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift +++ b/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift @@ -12,7 +12,7 @@ final class AccountListTableViewCell: UITableViewCell { private var _disposeBag = Set() var disposeBag = Set() - let avatarButton = CircleAvatarButton(frame: .zero) + let avatarButton = CircleAvatarButton() let nameLabel = MetaLabel(style: .accountListName) let usernameLabel = MetaLabel(style: .accountListUsername) let badgeButton = BadgeButton() diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift index 6d399c1b2..ab6f8eabd 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift @@ -17,17 +17,9 @@ open class AvatarButton: UIControl { public var size = CGSize(width: 46, height: 46) public let avatarImageView = AvatarImageView() - public override init(frame: CGRect) { - super.init(frame: frame) - _init() - } - - public required init?(coder: NSCoder) { - super.init(coder: coder) - _init() - } - - open func _init() { + public init(avatarPlaceholder: UIImage? = UIImage.placeholder(color: .systemFill)) { + super.init(frame: .zero) + avatarImageView.image = avatarPlaceholder avatarImageView.frame = bounds avatarImageView.translatesAutoresizingMaskIntoConstraints = false addSubview(avatarImageView) @@ -37,7 +29,9 @@ open class AvatarButton: UIControl { accessibilityLabel = L10n.Common.Controls.Status.showUserProfile accessibilityTraits.insert(.image) } - + + public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented")} + public override func layoutSubviews() { super.layoutSubviews() diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/CircleAvatarButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/CircleAvatarButton.swift index 1a6894eb3..6cf2cfadd 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Button/CircleAvatarButton.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Button/CircleAvatarButton.swift @@ -14,6 +14,12 @@ public final class CircleAvatarButton: AvatarButton { public var borderColor: UIColor = UIColor.systemFill public var borderWidth: CGFloat = 2.0 + + public init() { + super.init(avatarPlaceholder: .placeholder(color: .systemFill)) + } + + public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented")} public override func updateAppearance() { super.updateAppearance() diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift index cce4f0f60..6cceb071f 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift @@ -247,7 +247,7 @@ extension StatusView.ViewModel { ) .sink { image, url in let configuration: AvatarImageView.Configuration = { - if let image = image { + if let image { return AvatarImageView.Configuration(image: image) } else { return AvatarImageView.Configuration(url: url)