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