Begin implementing follow button on UserView (IOS-140)

This commit is contained in:
Marcus Kida 2023-04-25 10:54:10 +02:00
parent 3e14b9b6c5
commit 52fb1eff1f
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 62 additions and 5 deletions

View File

@ -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

View File

@ -13,6 +13,10 @@ import os
public final class UserView: UIView {
public enum ButtonState {
case none, follow, unfollow, blocked
}
public var disposeBag = Set<AnyCancellable>()
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)
}
}
}