mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Account collection item view
This commit is contained in:
parent
a2f84197ef
commit
5777120f35
2 changed files with 70 additions and 17 deletions
|
@ -18,11 +18,13 @@ public class AccountViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension AccountViewModel {
|
public extension AccountViewModel {
|
||||||
var avatarURL: URL {
|
var avatarURL: URL { accountService.account.avatar }
|
||||||
accountService.account.avatar
|
|
||||||
}
|
|
||||||
|
|
||||||
var note: NSAttributedString {
|
var displayName: String { accountService.account.displayName }
|
||||||
accountService.account.note.attributed
|
|
||||||
}
|
var accountName: String { "@".appending(accountService.account.acct) }
|
||||||
|
|
||||||
|
var note: NSAttributedString { accountService.account.note.attributed }
|
||||||
|
|
||||||
|
var emoji: [Emoji] { accountService.account.emojis }
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import UIKit
|
||||||
|
|
||||||
class AccountView: UIView {
|
class AccountView: UIView {
|
||||||
let avatarImageView = AnimatedImageView()
|
let avatarImageView = AnimatedImageView()
|
||||||
|
let displayNameLabel = UILabel()
|
||||||
|
let accountLabel = UILabel()
|
||||||
let noteTextView = TouchFallthroughTextView()
|
let noteTextView = TouchFallthroughTextView()
|
||||||
|
|
||||||
private var accountConfiguration: AccountContentConfiguration
|
private var accountConfiguration: AccountContentConfiguration
|
||||||
|
@ -38,20 +40,44 @@ extension AccountView: UIContentView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension AccountView {
|
private extension AccountView {
|
||||||
func initialSetup() {
|
static let spacing: CGFloat = 8
|
||||||
let baseStackView = UIStackView()
|
static let stackViewSpacing: CGFloat = 4
|
||||||
|
static let avatarDimension: CGFloat = 50
|
||||||
|
|
||||||
addSubview(baseStackView)
|
func initialSetup() {
|
||||||
baseStackView.translatesAutoresizingMaskIntoConstraints = false
|
let stackView = UIStackView()
|
||||||
baseStackView.addArrangedSubview(avatarImageView)
|
|
||||||
baseStackView.addArrangedSubview(noteTextView)
|
addSubview(avatarImageView)
|
||||||
|
addSubview(stackView)
|
||||||
|
avatarImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
avatarImageView.layer.cornerRadius = Self.avatarDimension / 2
|
||||||
|
avatarImageView.clipsToBounds = true
|
||||||
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.spacing = Self.stackViewSpacing
|
||||||
|
stackView.addArrangedSubview(displayNameLabel)
|
||||||
|
stackView.addArrangedSubview(accountLabel)
|
||||||
|
stackView.addArrangedSubview(noteTextView)
|
||||||
|
displayNameLabel.numberOfLines = 0
|
||||||
|
displayNameLabel.font = .preferredFont(forTextStyle: .headline)
|
||||||
|
displayNameLabel.adjustsFontForContentSizeCategory = true
|
||||||
|
accountLabel.numberOfLines = 0
|
||||||
|
accountLabel.font = .preferredFont(forTextStyle: .subheadline)
|
||||||
|
accountLabel.adjustsFontForContentSizeCategory = true
|
||||||
|
accountLabel.textColor = .secondaryLabel
|
||||||
noteTextView.isScrollEnabled = false
|
noteTextView.isScrollEnabled = false
|
||||||
|
noteTextView.backgroundColor = .clear
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
baseStackView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor),
|
avatarImageView.widthAnchor.constraint(equalToConstant: Self.avatarDimension),
|
||||||
baseStackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
avatarImageView.heightAnchor.constraint(equalToConstant: Self.avatarDimension),
|
||||||
baseStackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
|
avatarImageView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor),
|
||||||
baseStackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor)
|
avatarImageView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
||||||
|
avatarImageView.bottomAnchor.constraint(lessThanOrEqualTo: readableContentGuide.bottomAnchor),
|
||||||
|
stackView.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: Self.spacing),
|
||||||
|
stackView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor),
|
||||||
|
stackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
|
||||||
|
stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor)
|
||||||
])
|
])
|
||||||
|
|
||||||
applyAccountConfiguration()
|
applyAccountConfiguration()
|
||||||
|
@ -59,6 +85,31 @@ private extension AccountView {
|
||||||
|
|
||||||
func applyAccountConfiguration() {
|
func applyAccountConfiguration() {
|
||||||
avatarImageView.kf.setImage(with: accountConfiguration.viewModel.avatarURL)
|
avatarImageView.kf.setImage(with: accountConfiguration.viewModel.avatarURL)
|
||||||
noteTextView.attributedText = accountConfiguration.viewModel.note
|
|
||||||
|
if accountConfiguration.viewModel.displayName == "" {
|
||||||
|
displayNameLabel.isHidden = true
|
||||||
|
} else {
|
||||||
|
let mutableDisplayName = NSMutableAttributedString(string: accountConfiguration.viewModel.displayName)
|
||||||
|
|
||||||
|
mutableDisplayName.insert(emoji: accountConfiguration.viewModel.emoji, view: displayNameLabel)
|
||||||
|
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
|
||||||
|
displayNameLabel.attributedText = mutableDisplayName
|
||||||
|
}
|
||||||
|
|
||||||
|
accountLabel.text = accountConfiguration.viewModel.accountName
|
||||||
|
|
||||||
|
let noteFont = UIFont.preferredFont(forTextStyle: .callout)
|
||||||
|
let mutableNote = NSMutableAttributedString(attributedString: accountConfiguration.viewModel.note)
|
||||||
|
let noteRange = NSRange(location: 0, length: mutableNote.length)
|
||||||
|
|
||||||
|
mutableNote.removeAttribute(.font, range: noteRange)
|
||||||
|
mutableNote.addAttributes(
|
||||||
|
[.font: noteFont as Any,
|
||||||
|
.foregroundColor: UIColor.label],
|
||||||
|
range: noteRange)
|
||||||
|
mutableNote.insert(emoji: accountConfiguration.viewModel.emoji, view: noteTextView)
|
||||||
|
mutableNote.resizeAttachments(toLineHeight: noteFont.lineHeight)
|
||||||
|
|
||||||
|
noteTextView.attributedText = mutableNote
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue