mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Show booster avatar
This commit is contained in:
parent
d8bd825788
commit
f7e6278943
1 changed files with 38 additions and 10 deletions
|
@ -9,6 +9,7 @@ import ViewModels
|
||||||
|
|
||||||
final class StatusView: UIView {
|
final class StatusView: UIView {
|
||||||
let avatarImageView = SDAnimatedImageView()
|
let avatarImageView = SDAnimatedImageView()
|
||||||
|
let rebloggerAvatarImageView = SDAnimatedImageView()
|
||||||
let avatarButton = UIButton()
|
let avatarButton = UIButton()
|
||||||
let infoIcon = UIImageView()
|
let infoIcon = UIImageView()
|
||||||
let infoLabel = AnimatedAttachmentLabel()
|
let infoLabel = AnimatedAttachmentLabel()
|
||||||
|
@ -34,6 +35,7 @@ final class StatusView: UIView {
|
||||||
private let containerStackView = UIStackView()
|
private let containerStackView = UIStackView()
|
||||||
private let sideStackView = UIStackView()
|
private let sideStackView = UIStackView()
|
||||||
private let mainStackView = UIStackView()
|
private let mainStackView = UIStackView()
|
||||||
|
private let avatarContainerView = UIView()
|
||||||
private let nameAccountContainerStackView = UIStackView()
|
private let nameAccountContainerStackView = UIStackView()
|
||||||
private let nameAccountTimeStackView = UIStackView()
|
private let nameAccountTimeStackView = UIStackView()
|
||||||
private let contextParentTimeApplicationStackView = UIStackView()
|
private let contextParentTimeApplicationStackView = UIStackView()
|
||||||
|
@ -47,12 +49,17 @@ final class StatusView: UIView {
|
||||||
private let inReplyToView = UIView()
|
private let inReplyToView = UIView()
|
||||||
private let hasReplyFollowingView = UIView()
|
private let hasReplyFollowingView = UIView()
|
||||||
private var statusConfiguration: StatusContentConfiguration
|
private var statusConfiguration: StatusContentConfiguration
|
||||||
private var infoIconCenterYConstraint: NSLayoutConstraint?
|
private let avatarWidthConstraint: NSLayoutConstraint
|
||||||
|
private let avatarHeightConstraint: NSLayoutConstraint
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
|
||||||
init(configuration: StatusContentConfiguration) {
|
init(configuration: StatusContentConfiguration) {
|
||||||
self.statusConfiguration = configuration
|
self.statusConfiguration = configuration
|
||||||
|
|
||||||
|
avatarWidthConstraint = avatarImageView.widthAnchor.constraint(equalToConstant: .avatarDimension)
|
||||||
|
avatarHeightConstraint = avatarImageView.heightAnchor.constraint(equalToConstant: .avatarDimension)
|
||||||
|
avatarHeightConstraint.priority = .justBelowMax
|
||||||
|
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
|
|
||||||
initialSetup()
|
initialSetup()
|
||||||
|
@ -142,6 +149,7 @@ extension StatusView: UITextViewDelegate {
|
||||||
|
|
||||||
private extension StatusView {
|
private extension StatusView {
|
||||||
static let actionButtonTitleEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 0)
|
static let actionButtonTitleEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 0)
|
||||||
|
static let reblogAvatarDimension: CGFloat = .avatarDimension * 7 / 8
|
||||||
|
|
||||||
var actionButtons: [UIButton] {
|
var actionButtons: [UIButton] {
|
||||||
[replyButton, reblogButton, favoriteButton, shareButton, menuButton]
|
[replyButton, reblogButton, favoriteButton, shareButton, menuButton]
|
||||||
|
@ -359,13 +367,11 @@ private extension StatusView {
|
||||||
buttonsStackView.distribution = .equalSpacing
|
buttonsStackView.distribution = .equalSpacing
|
||||||
mainStackView.addArrangedSubview(buttonsStackView)
|
mainStackView.addArrangedSubview(buttonsStackView)
|
||||||
|
|
||||||
|
avatarContainerView.addSubview(avatarImageView)
|
||||||
|
avatarImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
avatarImageView.layer.cornerRadius = .avatarDimension / 2
|
avatarImageView.layer.cornerRadius = .avatarDimension / 2
|
||||||
avatarImageView.clipsToBounds = true
|
avatarImageView.clipsToBounds = true
|
||||||
|
|
||||||
let avatarHeightConstraint = avatarImageView.heightAnchor.constraint(equalToConstant: .avatarDimension)
|
|
||||||
|
|
||||||
avatarHeightConstraint.priority = .justBelowMax
|
|
||||||
|
|
||||||
avatarButton.translatesAutoresizingMaskIntoConstraints = false
|
avatarButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
avatarImageView.addSubview(avatarButton)
|
avatarImageView.addSubview(avatarButton)
|
||||||
avatarImageView.isUserInteractionEnabled = true
|
avatarImageView.isUserInteractionEnabled = true
|
||||||
|
@ -375,6 +381,12 @@ private extension StatusView {
|
||||||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.accountSelected() },
|
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.accountSelected() },
|
||||||
for: .touchUpInside)
|
for: .touchUpInside)
|
||||||
|
|
||||||
|
avatarContainerView.addSubview(rebloggerAvatarImageView)
|
||||||
|
rebloggerAvatarImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
rebloggerAvatarImageView.layer.cornerRadius = .avatarDimension / 4
|
||||||
|
rebloggerAvatarImageView.clipsToBounds = true
|
||||||
|
rebloggerAvatarImageView.isHidden = true
|
||||||
|
|
||||||
for view in [inReplyToView, hasReplyFollowingView] {
|
for view in [inReplyToView, hasReplyFollowingView] {
|
||||||
addSubview(view)
|
addSubview(view)
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
@ -392,8 +404,16 @@ private extension StatusView {
|
||||||
containerStackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
containerStackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
||||||
containerStackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
|
containerStackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
|
||||||
containerStackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor),
|
containerStackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor),
|
||||||
avatarImageView.widthAnchor.constraint(equalToConstant: .avatarDimension),
|
avatarContainerView.widthAnchor.constraint(equalToConstant: .avatarDimension),
|
||||||
|
avatarContainerView.heightAnchor.constraint(equalToConstant: .avatarDimension),
|
||||||
|
avatarWidthConstraint,
|
||||||
avatarHeightConstraint,
|
avatarHeightConstraint,
|
||||||
|
avatarImageView.topAnchor.constraint(equalTo: avatarContainerView.topAnchor),
|
||||||
|
avatarImageView.leadingAnchor.constraint(equalTo: avatarContainerView.leadingAnchor),
|
||||||
|
rebloggerAvatarImageView.widthAnchor.constraint(equalToConstant: .avatarDimension / 2),
|
||||||
|
rebloggerAvatarImageView.heightAnchor.constraint(equalToConstant: .avatarDimension / 2),
|
||||||
|
rebloggerAvatarImageView.trailingAnchor.constraint(equalTo: avatarContainerView.trailingAnchor),
|
||||||
|
rebloggerAvatarImageView.bottomAnchor.constraint(equalTo: avatarContainerView.bottomAnchor),
|
||||||
sideStackView.widthAnchor.constraint(equalToConstant: .avatarDimension),
|
sideStackView.widthAnchor.constraint(equalToConstant: .avatarDimension),
|
||||||
avatarButton.leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
|
avatarButton.leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
|
||||||
avatarButton.topAnchor.constraint(equalTo: avatarImageView.topAnchor),
|
avatarButton.topAnchor.constraint(equalTo: avatarImageView.topAnchor),
|
||||||
|
@ -434,10 +454,18 @@ private extension StatusView {
|
||||||
|
|
||||||
sideStackView.isHidden = isContextParent
|
sideStackView.isHidden = isContextParent
|
||||||
|
|
||||||
if isContextParent, avatarImageView.superview !== nameAccountContainerStackView {
|
let avatarDimension = viewModel.isReblog ? Self.reblogAvatarDimension : .avatarDimension
|
||||||
nameAccountContainerStackView.insertArrangedSubview(avatarImageView, at: 0)
|
|
||||||
} else if avatarImageView.superview !== sideStackView {
|
avatarWidthConstraint.constant = avatarDimension
|
||||||
sideStackView.insertArrangedSubview(avatarImageView, at: 1)
|
avatarHeightConstraint.constant = avatarDimension
|
||||||
|
avatarImageView.layer.cornerRadius = avatarDimension / 2
|
||||||
|
rebloggerAvatarImageView.isHidden = !viewModel.isReblog
|
||||||
|
rebloggerAvatarImageView.sd_setImage(with: viewModel.isReblog ? viewModel.rebloggerAvatarURL : nil)
|
||||||
|
|
||||||
|
if isContextParent, avatarContainerView.superview !== nameAccountContainerStackView {
|
||||||
|
nameAccountContainerStackView.insertArrangedSubview(avatarContainerView, at: 0)
|
||||||
|
} else if avatarContainerView.superview !== sideStackView {
|
||||||
|
sideStackView.insertArrangedSubview(avatarContainerView, at: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
|
Loading…
Reference in a new issue