diff --git a/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell.swift index ecd88d738..9dcec469f 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/UserTableViewCell.swift @@ -19,7 +19,11 @@ final class UserTableViewCell: UITableViewCell { weak var delegate: UserTableViewCellDelegate? - let userView = UserView() + let userView: UserView = { + let view = UserView() +// view.setButtonState(.follow) + return view + }() let separatorLine = UIView.separatorLine diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift index 10c70dd21..cc64db73c 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/UserView.swift @@ -13,6 +13,10 @@ import os public final class UserView: UIView { + public enum ButtonState { + case none, follow, unfollow, blocked + } + public var disposeBag = Set() public private(set) lazy var viewModel: ViewModel = { @@ -85,16 +89,35 @@ public final class UserView: UIView { return label }() - public func setFollowButtonEnabled(_ enabled: Bool) { - switch enabled { - case true: + private let followButton: UIButton = { + let button = FollowButton() + button.cornerRadius = 10 + button.setTitle("Follow", for: .normal) + button.isHidden = true + button.translatesAutoresizingMaskIntoConstraints = false + button.setContentCompressionResistancePriority(.required, for: .horizontal) + button.setContentHuggingPriority(.required, for: .horizontal) + + NSLayoutConstraint.activate([ + button.widthAnchor.constraint(equalToConstant: 96), + button.heightAnchor.constraint(equalToConstant: 36) + ]) + + return button + }() + + public func setButtonState(_ state: ButtonState) { + switch state { + case .follow, .unfollow, .blocked: verifiedStackView.axis = .vertical verifiedStackView.alignment = .leading verifiedStackCenterSpacerView.isHidden = true - case false: + followButton.isHidden = false + case .none: verifiedStackView.axis = .horizontal verifiedStackView.alignment = .leading verifiedStackCenterSpacerView.isHidden = false + followButton.isHidden = true } } @@ -142,6 +165,9 @@ extension UserView { labelStackView.axis = .vertical containerStackView.addArrangedSubview(labelStackView) + // follow button + containerStackView.addArrangedSubview(followButton) + let nameStackView = UIStackView() nameStackView.axis = .horizontal @@ -193,3 +219,30 @@ extension UserView { } } + +private final class FollowButton: RoundedEdgesButton { + + init() { + super.init(frame: .zero) + configureAppearance() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func configureAppearance() { + setTitleColor(Asset.Colors.Label.primaryReverse.color, for: .normal) + setTitleColor(Asset.Colors.Label.primaryReverse.color.withAlphaComponent(0.5), for: .highlighted) + switch traitCollection.userInterfaceStyle { + case .dark: + setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundDark.color), for: .normal) + setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedDark.color), for: .highlighted) + setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedDark.color), for: .disabled) + default: + setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundLight.color), for: .normal) + setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedLight.color), for: .highlighted) + setBackgroundImage(.placeholder(color: Asset.Scene.Profile.RelationshipButton.backgroundHighlightedLight.color), for: .disabled) + } + } +}