From f3107094c93561c0de642cc01b8d75879133b850 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Mon, 18 Jan 2021 23:29:00 -0800 Subject: [PATCH] Header improvements --- Views/AccountHeaderView.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Views/AccountHeaderView.swift b/Views/AccountHeaderView.swift index 39db866..e2f57ad 100644 --- a/Views/AccountHeaderView.swift +++ b/Views/AccountHeaderView.swift @@ -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),