This commit is contained in:
Justin Mazzocchi 2020-09-28 18:32:28 -07:00
parent a7e6db409a
commit 7335615b64
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
7 changed files with 47 additions and 42 deletions

View file

@ -57,8 +57,6 @@ extension AccountView: UITextViewDelegate {
} }
private extension AccountView { private extension AccountView {
static let spacing: CGFloat = 8
static let stackViewSpacing: CGFloat = 4
static let avatarDimension: CGFloat = 50 static let avatarDimension: CGFloat = 50
func initialSetup() { func initialSetup() {
@ -71,7 +69,7 @@ private extension AccountView {
avatarImageView.clipsToBounds = true avatarImageView.clipsToBounds = true
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical stackView.axis = .vertical
stackView.spacing = Self.stackViewSpacing stackView.spacing = .compactSpacing
stackView.addArrangedSubview(displayNameLabel) stackView.addArrangedSubview(displayNameLabel)
stackView.addArrangedSubview(accountLabel) stackView.addArrangedSubview(accountLabel)
stackView.addArrangedSubview(noteTextView) stackView.addArrangedSubview(noteTextView)
@ -92,7 +90,7 @@ private extension AccountView {
avatarImageView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor), avatarImageView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor),
avatarImageView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor), avatarImageView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
avatarImageView.bottomAnchor.constraint(lessThanOrEqualTo: readableContentGuide.bottomAnchor), avatarImageView.bottomAnchor.constraint(lessThanOrEqualTo: readableContentGuide.bottomAnchor),
stackView.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: Self.spacing), stackView.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: .defaultSpacing),
stackView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor), stackView.topAnchor.constraint(equalTo: readableContentGuide.topAnchor),
stackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor), stackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor) stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor)

View file

@ -17,23 +17,12 @@ final class AttachmentView: UIView {
layoutMargins = .zero layoutMargins = .zero
addSubview(imageView) addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
imageView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor).isActive = true
imageView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
imageView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
imageView.contentMode = .scaleAspectFill imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true imageView.clipsToBounds = true
addSubview(button) addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false button.translatesAutoresizingMaskIntoConstraints = false
button.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true button.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
button.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor).isActive = true
button.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
button.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
let highlightedButtonBackgroundImage = UIColor(white: 0, alpha: 0.5).image()
button.setBackgroundImage(highlightedButtonBackgroundImage, for: .highlighted)
switch viewModel.attachment.type { switch viewModel.attachment.type {
case .image: case .image:
@ -41,6 +30,17 @@ final class AttachmentView: UIView {
default: default:
break break
} }
NSLayoutConstraint.activate([
imageView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
imageView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
imageView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
imageView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor),
button.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
button.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
button.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
button.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
])
} }
@available(*, unavailable) @available(*, unavailable)

View file

@ -47,29 +47,30 @@ final class AttachmentsView: UIView {
} }
private extension AttachmentsView { private extension AttachmentsView {
static let spacing: CGFloat = 4
static let cornerRadius: CGFloat = 8
func initializationActions() { func initializationActions() {
backgroundColor = .clear backgroundColor = .clear
layoutMargins = .zero layoutMargins = .zero
clipsToBounds = true clipsToBounds = true
layer.cornerRadius = Self.cornerRadius layer.cornerRadius = .defaultCornerRadius
addSubview(containerStackView) addSubview(containerStackView)
containerStackView.translatesAutoresizingMaskIntoConstraints = false containerStackView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.distribution = .fillEqually containerStackView.distribution = .fillEqually
containerStackView.spacing = Self.spacing containerStackView.spacing = .compactSpacing
containerStackView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
containerStackView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor).isActive = true
containerStackView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
containerStackView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
leftStackView.distribution = .fillEqually leftStackView.distribution = .fillEqually
leftStackView.spacing = Self.spacing leftStackView.spacing = .compactSpacing
leftStackView.axis = .vertical leftStackView.axis = .vertical
rightStackView.distribution = .fillEqually rightStackView.distribution = .fillEqually
rightStackView.spacing = Self.spacing rightStackView.spacing = .compactSpacing
rightStackView.axis = .vertical rightStackView.axis = .vertical
containerStackView.addArrangedSubview(leftStackView) containerStackView.addArrangedSubview(leftStackView)
containerStackView.addArrangedSubview(rightStackView) containerStackView.addArrangedSubview(rightStackView)
NSLayoutConstraint.activate([
containerStackView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
containerStackView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
containerStackView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
containerStackView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
])
} }
} }

View file

@ -10,9 +10,13 @@ final class LoadingTableFooterView: UIView {
addSubview(activityIndicatorView) addSubview(activityIndicatorView)
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
activityIndicatorView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true NSLayoutConstraint.activate([
activityIndicatorView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor),
activityIndicatorView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
activityIndicatorView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
])
activityIndicatorView.startAnimating() activityIndicatorView.startAnimating()
} }

View file

@ -104,6 +104,7 @@ extension StatusView: UITextViewDelegate {
} }
private extension StatusView { private extension StatusView {
// swiftlint:disable function_body_length
func initialSetup() { func initialSetup() {
Bundle.main.loadNibNamed(String(describing: type(of: self)), owner: self, options: nil) Bundle.main.loadNibNamed(String(describing: type(of: self)), owner: self, options: nil)
@ -132,10 +133,8 @@ private extension StatusView {
contentTextView.delegate = self contentTextView.delegate = self
let highlightedButtonBackgroundImage = UIColor(white: 0, alpha: 0.5).image() avatarButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
contextParentAvatarButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
avatarButton.setBackgroundImage(highlightedButtonBackgroundImage, for: .highlighted)
contextParentAvatarButton.setBackgroundImage(highlightedButtonBackgroundImage, for: .highlighted)
let accountAction = UIAction { [weak self] _ in self?.statusConfiguration.viewModel.accountSelected() } let accountAction = UIAction { [weak self] _ in self?.statusConfiguration.viewModel.accountSelected() }
@ -173,7 +172,6 @@ private extension StatusView {
applyStatusConfiguration() applyStatusConfiguration()
} }
// swiftlint:disable function_body_length
func applyStatusConfiguration() { func applyStatusConfiguration() {
let viewModel = statusConfiguration.viewModel let viewModel = statusConfiguration.viewModel
let mutableContent = NSMutableAttributedString(attributedString: viewModel.content) let mutableContent = NSMutableAttributedString(attributedString: viewModel.content)

View file

@ -8,6 +8,10 @@ extension CGFloat {
static let defaultCornerRadius: Self = 8 static let defaultCornerRadius: Self = 8
} }
extension TimeInterval {
static let defaultAnimationDuration: Self = 0.5
}
extension UIImage { extension UIImage {
static let highlightedButtonBackground = UIColor(white: 0, alpha: 0.5).image() static let highlightedButtonBackground = UIColor(white: 0, alpha: 0.5).image()
} }

View file

@ -9,7 +9,7 @@ class WebfingerIndicatorView: UIVisualEffectView {
super.init(effect: nil) super.init(effect: nil)
clipsToBounds = true clipsToBounds = true
layer.cornerRadius = 8 layer.cornerRadius = .defaultCornerRadius
contentView.addSubview(activityIndicatorView) contentView.addSubview(activityIndicatorView)
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
@ -17,13 +17,13 @@ class WebfingerIndicatorView: UIVisualEffectView {
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
trailingAnchor.constraint( trailingAnchor.constraint(
equalTo: activityIndicatorView.trailingAnchor, constant: 8), equalTo: activityIndicatorView.trailingAnchor, constant: .defaultSpacing),
bottomAnchor.constraint( bottomAnchor.constraint(
equalTo: activityIndicatorView.bottomAnchor, constant: 8), equalTo: activityIndicatorView.bottomAnchor, constant: .defaultSpacing),
activityIndicatorView.topAnchor.constraint( activityIndicatorView.topAnchor.constraint(
equalTo: topAnchor, constant: 8), equalTo: topAnchor, constant: .defaultSpacing),
activityIndicatorView.leadingAnchor.constraint( activityIndicatorView.leadingAnchor.constraint(
equalTo: leadingAnchor, constant: 8), equalTo: leadingAnchor, constant: .defaultSpacing),
activityIndicatorView.centerXAnchor.constraint( activityIndicatorView.centerXAnchor.constraint(
equalTo: contentView.safeAreaLayoutGuide.centerXAnchor), equalTo: contentView.safeAreaLayoutGuide.centerXAnchor),
activityIndicatorView.centerYAnchor.constraint( activityIndicatorView.centerYAnchor.constraint(
@ -44,15 +44,15 @@ extension WebfingerIndicatorView {
isHidden = false isHidden = false
activityIndicatorView.startAnimating() activityIndicatorView.startAnimating()
UIView.animate(withDuration: 0.5) { UIView.animate(withDuration: .defaultAnimationDuration) {
self.effect = UIBlurEffect(style: .systemUltraThinMaterial) self.effect = UIBlurEffect(style: .systemChromeMaterial)
} }
} }
func stopAnimating() { func stopAnimating() {
activityIndicatorView.stopAnimating() activityIndicatorView.stopAnimating()
UIView.animate(withDuration: 0.5) { UIView.animate(withDuration: .defaultAnimationDuration) {
self.effect = nil self.effect = nil
} completion: { _ in } completion: { _ in
self.isHidden = true self.isHidden = true