Header improvements

This commit is contained in:
Justin Mazzocchi 2021-01-18 23:29:00 -08:00
parent 0f4c2f6d01
commit f3107094c9
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C

View file

@ -5,6 +5,7 @@ import UIKit
import ViewModels
final class AccountHeaderView: UIView {
let headerImageBackgroundView = UIView()
let headerImageView = AnimatedImageView()
let headerButton = UIButton()
let avatarBackgroundView = UIView()
@ -27,7 +28,11 @@ final class AccountHeaderView: UIView {
var viewModel: ProfileViewModel? {
didSet {
if let accountViewModel = viewModel?.accountViewModel {
headerImageView.kf.setImage(with: accountViewModel.headerURL)
headerImageView.kf.setImage(with: accountViewModel.headerURL) { [weak self] in
if case let .success(result) = $0, result.image.size != Self.missingHeaderImageSize {
self?.headerButton.isEnabled = true
}
}
headerImageView.tag = accountViewModel.headerURL.hashValue
avatarImageView.kf.setImage(with: accountViewModel.avatarURL(profile: true))
avatarImageView.tag = accountViewModel.avatarURL(profile: true).hashValue
@ -161,11 +166,16 @@ extension AccountHeaderView: UITextViewDelegate {
private extension AccountHeaderView {
static let avatarDimension = CGFloat.avatarDimension * 2
static let missingHeaderImageSize = CGSize(width: 1, height: 1)
// swiftlint:disable:next function_body_length
func initialSetup() {
let baseStackView = UIStackView()
addSubview(headerImageBackgroundView)
headerImageBackgroundView.translatesAutoresizingMaskIntoConstraints = false
headerImageBackgroundView.backgroundColor = .secondarySystemBackground
addSubview(headerImageView)
headerImageView.translatesAutoresizingMaskIntoConstraints = false
headerImageView.contentMode = .scaleAspectFill
@ -177,6 +187,7 @@ private extension AccountHeaderView {
headerButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
headerButton.addAction(UIAction { [weak self] _ in self?.viewModel?.presentHeader() }, for: .touchUpInside)
headerButton.isEnabled = false
let avatarBackgroundViewDimension = Self.avatarDimension + .compactSpacing * 2
@ -320,6 +331,10 @@ private extension AccountHeaderView {
headerImageView.topAnchor.constraint(equalTo: topAnchor),
headerImageView.leadingAnchor.constraint(equalTo: leadingAnchor),
headerImageView.trailingAnchor.constraint(equalTo: trailingAnchor),
headerImageBackgroundView.leadingAnchor.constraint(equalTo: headerImageView.leadingAnchor),
headerImageBackgroundView.topAnchor.constraint(equalTo: headerImageView.topAnchor),
headerImageBackgroundView.trailingAnchor.constraint(equalTo: headerImageView.trailingAnchor),
headerImageBackgroundView.bottomAnchor.constraint(equalTo: headerImageView.bottomAnchor),
headerButton.leadingAnchor.constraint(equalTo: headerImageView.leadingAnchor),
headerButton.topAnchor.constraint(equalTo: headerImageView.topAnchor),
headerButton.bottomAnchor.constraint(equalTo: headerImageView.bottomAnchor),