From 5932d00f2fba696a856cc1eb5d088477ced5fd4b Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Fri, 2 Dec 2022 22:55:16 -0500 Subject: [PATCH] add a divider between the image and the text in the card --- .../MastodonExtension/NSLayoutConstraint.swift | 12 ++++++++++++ .../MastodonUI/View/Content/StatusCardControl.swift | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/MastodonSDK/Sources/MastodonExtension/NSLayoutConstraint.swift b/MastodonSDK/Sources/MastodonExtension/NSLayoutConstraint.swift index 057b17859..3251eb58b 100644 --- a/MastodonSDK/Sources/MastodonExtension/NSLayoutConstraint.swift +++ b/MastodonSDK/Sources/MastodonExtension/NSLayoutConstraint.swift @@ -17,4 +17,16 @@ extension NSLayoutConstraint { self.identifier = identifier return self } + + @discardableResult + public func activate() -> Self { + self.isActive = true + return self + } + + @discardableResult + public func deactivate() -> Self { + self.isActive = false + return self + } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift index bffa56f0f..dc8efc6c0 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift @@ -22,6 +22,7 @@ public final class StatusCardControl: UIControl { private let labelStackView = UIStackView() private let highlightView = UIView() + private let dividerView = UIView() private let imageView = UIImageView() private let titleLabel = UILabel() private let linkLabel = UILabel() @@ -31,6 +32,7 @@ public final class StatusCardControl: UIControl { private var layout: Layout? private var layoutConstraints: [NSLayoutConstraint] = [] + private var dividerConstraint: NSLayoutConstraint? public override var isHighlighted: Bool { didSet { @@ -88,6 +90,7 @@ public final class StatusCardControl: UIControl { labelStackView.spacing = 2 containerStackView.addArrangedSubview(imageView) + containerStackView.addArrangedSubview(dividerView) containerStackView.addArrangedSubview(labelStackView) containerStackView.isUserInteractionEnabled = false containerStackView.distribution = .fill @@ -146,6 +149,7 @@ public final class StatusCardControl: UIControl { if let window = window { layer.borderWidth = 1 / window.screen.scale + dividerConstraint?.constant = 1 / window.screen.scale } } @@ -154,7 +158,9 @@ public final class StatusCardControl: UIControl { self.layout = layout NSLayoutConstraint.deactivate(layoutConstraints) + dividerConstraint?.deactivate() + let pixelSize = 1 / (window?.screen.scale ?? 1) switch layout { case .large(let aspectRatio): containerStackView.alignment = .fill @@ -169,8 +175,9 @@ public final class StatusCardControl: UIControl { .priority(.defaultLow - 1), // set a reasonable max height for very tall images imageView.heightAnchor - .constraint(lessThanOrEqualToConstant: 400) + .constraint(lessThanOrEqualToConstant: 400), ] + dividerConstraint = dividerView.heightAnchor.constraint(equalToConstant: pixelSize).activate() case .compact: containerStackView.alignment = .center containerStackView.axis = .horizontal @@ -178,8 +185,9 @@ public final class StatusCardControl: UIControl { imageView.heightAnchor.constraint(equalTo: heightAnchor), imageView.widthAnchor.constraint(equalToConstant: 85), heightAnchor.constraint(equalToConstant: 85).priority(.defaultLow - 1), - heightAnchor.constraint(greaterThanOrEqualToConstant: 85) + heightAnchor.constraint(greaterThanOrEqualToConstant: 85), ] + dividerConstraint = dividerView.widthAnchor.constraint(equalToConstant: pixelSize).activate() } if let webView { @@ -201,6 +209,7 @@ public final class StatusCardControl: UIControl { private func apply(theme: Theme) { layer.borderColor = theme.separator.cgColor + dividerView.backgroundColor = theme.separator imageView.backgroundColor = theme.systemElevatedBackgroundColor } }