mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 01:31:02 +00:00
Header improvements
This commit is contained in:
parent
0f4c2f6d01
commit
f3107094c9
1 changed files with 16 additions and 1 deletions
|
@ -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),
|
||||||
|
|
Loading…
Reference in a new issue