Begin implementing follow button on UserView (IOS-140)
This commit is contained in:
parent
3e14b9b6c5
commit
52fb1eff1f
|
@ -19,7 +19,11 @@ final class UserTableViewCell: UITableViewCell {
|
||||||
|
|
||||||
weak var delegate: UserTableViewCellDelegate?
|
weak var delegate: UserTableViewCellDelegate?
|
||||||
|
|
||||||
let userView = UserView()
|
let userView: UserView = {
|
||||||
|
let view = UserView()
|
||||||
|
// view.setButtonState(.follow)
|
||||||
|
return view
|
||||||
|
}()
|
||||||
|
|
||||||
let separatorLine = UIView.separatorLine
|
let separatorLine = UIView.separatorLine
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@ import os
|
||||||
|
|
||||||
public final class UserView: UIView {
|
public final class UserView: UIView {
|
||||||
|
|
||||||
|
public enum ButtonState {
|
||||||
|
case none, follow, unfollow, blocked
|
||||||
|
}
|
||||||
|
|
||||||
public var disposeBag = Set<AnyCancellable>()
|
public var disposeBag = Set<AnyCancellable>()
|
||||||
|
|
||||||
public private(set) lazy var viewModel: ViewModel = {
|
public private(set) lazy var viewModel: ViewModel = {
|
||||||
|
@ -85,16 +89,35 @@ public final class UserView: UIView {
|
||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
|
|
||||||
public func setFollowButtonEnabled(_ enabled: Bool) {
|
private let followButton: UIButton = {
|
||||||
switch enabled {
|
let button = FollowButton()
|
||||||
case true:
|
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.axis = .vertical
|
||||||
verifiedStackView.alignment = .leading
|
verifiedStackView.alignment = .leading
|
||||||
verifiedStackCenterSpacerView.isHidden = true
|
verifiedStackCenterSpacerView.isHidden = true
|
||||||
case false:
|
followButton.isHidden = false
|
||||||
|
case .none:
|
||||||
verifiedStackView.axis = .horizontal
|
verifiedStackView.axis = .horizontal
|
||||||
verifiedStackView.alignment = .leading
|
verifiedStackView.alignment = .leading
|
||||||
verifiedStackCenterSpacerView.isHidden = false
|
verifiedStackCenterSpacerView.isHidden = false
|
||||||
|
followButton.isHidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +165,9 @@ extension UserView {
|
||||||
labelStackView.axis = .vertical
|
labelStackView.axis = .vertical
|
||||||
containerStackView.addArrangedSubview(labelStackView)
|
containerStackView.addArrangedSubview(labelStackView)
|
||||||
|
|
||||||
|
// follow button
|
||||||
|
containerStackView.addArrangedSubview(followButton)
|
||||||
|
|
||||||
let nameStackView = UIStackView()
|
let nameStackView = UIStackView()
|
||||||
nameStackView.axis = .horizontal
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue