Change name and improve a11y
This commit is contained in:
parent
4616d40519
commit
3a90b1c865
|
@ -12,7 +12,7 @@ import MastodonCore
|
||||||
import CoreDataStack
|
import CoreDataStack
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public final class LinkPreviewButton: UIControl {
|
public final class StatusCardControl: UIControl {
|
||||||
private var disposeBag = Set<AnyCancellable>()
|
private var disposeBag = Set<AnyCancellable>()
|
||||||
|
|
||||||
private let containerStackView = UIStackView()
|
private let containerStackView = UIStackView()
|
||||||
|
@ -25,21 +25,23 @@ public final class LinkPreviewButton: UIControl {
|
||||||
|
|
||||||
private lazy var compactImageConstraints = [
|
private lazy var compactImageConstraints = [
|
||||||
imageView.heightAnchor.constraint(equalTo: heightAnchor),
|
imageView.heightAnchor.constraint(equalTo: heightAnchor),
|
||||||
imageView.widthAnchor.constraint(equalTo: heightAnchor),
|
imageView.widthAnchor.constraint(equalToConstant: 85),
|
||||||
heightAnchor.constraint(equalToConstant: 85),
|
heightAnchor.constraint(equalToConstant: 85).priority(.defaultLow - 1),
|
||||||
|
heightAnchor.constraint(greaterThanOrEqualToConstant: 85)
|
||||||
]
|
]
|
||||||
|
|
||||||
private lazy var largeImageConstraints = [
|
private lazy var largeImageConstraints = [
|
||||||
imageView.heightAnchor.constraint(
|
imageView.heightAnchor.constraint(
|
||||||
equalTo: imageView.widthAnchor,
|
equalTo: imageView.widthAnchor,
|
||||||
multiplier: 21 / 40
|
multiplier: 21 / 40
|
||||||
).priority(.defaultLow - 1),
|
)
|
||||||
|
// This priority is important or constraints break;
|
||||||
|
// it still renders the card correctly.
|
||||||
|
.priority(.defaultLow - 1),
|
||||||
]
|
]
|
||||||
|
|
||||||
public override var isHighlighted: Bool {
|
public override var isHighlighted: Bool {
|
||||||
didSet {
|
didSet { highlightView.isHidden = !isHighlighted }
|
||||||
highlightView.isHidden = !isHighlighted
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
|
@ -55,6 +57,10 @@ public final class LinkPreviewButton: UIControl {
|
||||||
layer.cornerCurve = .continuous
|
layer.cornerCurve = .continuous
|
||||||
layer.cornerRadius = 10
|
layer.cornerRadius = 10
|
||||||
|
|
||||||
|
if #available(iOS 15, *) {
|
||||||
|
maximumContentSizeCategory = .accessibilityLarge
|
||||||
|
}
|
||||||
|
|
||||||
highlightView.backgroundColor = UIColor.black.withAlphaComponent(0.1)
|
highlightView.backgroundColor = UIColor.black.withAlphaComponent(0.1)
|
||||||
highlightView.isHidden = true
|
highlightView.isHidden = true
|
||||||
|
|
||||||
|
@ -101,6 +107,12 @@ public final class LinkPreviewButton: UIControl {
|
||||||
public func configure(card: Card) {
|
public func configure(card: Card) {
|
||||||
let isCompact = card.width == card.height
|
let isCompact = card.width == card.height
|
||||||
|
|
||||||
|
if let host = card.url?.host {
|
||||||
|
accessibilityLabel = "\(card.title) \(host)"
|
||||||
|
} else {
|
||||||
|
accessibilityLabel = card.title
|
||||||
|
}
|
||||||
|
|
||||||
titleLabel.text = card.title
|
titleLabel.text = card.title
|
||||||
linkLabel.text = card.url?.host
|
linkLabel.text = card.url?.host
|
||||||
imageView.contentMode = .center
|
imageView.contentMode = .center
|
|
@ -316,7 +316,7 @@ extension StatusView.ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
statusView.contentMetaText.textView.alpha = isContentReveal ? 1 : 0 // keep the frame size and only display when revealing
|
statusView.contentMetaText.textView.alpha = isContentReveal ? 1 : 0 // keep the frame size and only display when revealing
|
||||||
statusView.linkPreviewButton.alpha = isContentReveal ? 1 : 0
|
statusView.statusCardControl.alpha = isContentReveal ? 1 : 0
|
||||||
|
|
||||||
statusView.setSpoilerOverlayViewHidden(isHidden: isContentReveal)
|
statusView.setSpoilerOverlayViewHidden(isHidden: isContentReveal)
|
||||||
|
|
||||||
|
@ -490,8 +490,8 @@ extension StatusView.ViewModel {
|
||||||
private func bindCard(statusView: StatusView) {
|
private func bindCard(statusView: StatusView) {
|
||||||
$card.sink { card in
|
$card.sink { card in
|
||||||
guard let card = card else { return }
|
guard let card = card else { return }
|
||||||
statusView.linkPreviewButton.configure(card: card)
|
statusView.statusCardControl.configure(card: card)
|
||||||
statusView.setLinkPreviewButtonDisplay()
|
statusView.setStatusCardControlDisplay()
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ public final class StatusView: UIView {
|
||||||
return metaText
|
return metaText
|
||||||
}()
|
}()
|
||||||
|
|
||||||
public let linkPreviewButton = LinkPreviewButton()
|
public let statusCardControl = StatusCardControl()
|
||||||
|
|
||||||
// content warning
|
// content warning
|
||||||
public let spoilerOverlayView = SpoilerOverlayView()
|
public let spoilerOverlayView = SpoilerOverlayView()
|
||||||
|
@ -220,7 +220,7 @@ public final class StatusView: UIView {
|
||||||
setMediaDisplay(isDisplay: false)
|
setMediaDisplay(isDisplay: false)
|
||||||
setPollDisplay(isDisplay: false)
|
setPollDisplay(isDisplay: false)
|
||||||
setFilterHintLabelDisplay(isDisplay: false)
|
setFilterHintLabelDisplay(isDisplay: false)
|
||||||
setLinkPreviewButtonDisplay(isDisplay: false)
|
setStatusCardControlDisplay(isDisplay: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
|
@ -261,16 +261,13 @@ extension StatusView {
|
||||||
// content
|
// content
|
||||||
contentMetaText.textView.delegate = self
|
contentMetaText.textView.delegate = self
|
||||||
contentMetaText.textView.linkDelegate = self
|
contentMetaText.textView.linkDelegate = self
|
||||||
|
|
||||||
|
// card
|
||||||
|
statusCardControl.addTarget(self, action: #selector(statusCardControlPressed), for: .touchUpInside)
|
||||||
|
|
||||||
// media
|
// media
|
||||||
mediaGridContainerView.delegate = self
|
mediaGridContainerView.delegate = self
|
||||||
|
|
||||||
linkPreviewButton.addTarget(
|
|
||||||
self,
|
|
||||||
action: #selector(linkPreviewButtonPressed),
|
|
||||||
for: .touchUpInside
|
|
||||||
)
|
|
||||||
|
|
||||||
// poll
|
// poll
|
||||||
pollTableView.translatesAutoresizingMaskIntoConstraints = false
|
pollTableView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
pollTableViewHeightLayoutConstraint = pollTableView.heightAnchor.constraint(equalToConstant: 44.0).priority(.required - 1)
|
pollTableViewHeightLayoutConstraint = pollTableView.heightAnchor.constraint(equalToConstant: 44.0).priority(.required - 1)
|
||||||
|
@ -306,7 +303,7 @@ extension StatusView {
|
||||||
delegate?.statusView(self, spoilerOverlayViewDidPressed: spoilerOverlayView)
|
delegate?.statusView(self, spoilerOverlayViewDidPressed: spoilerOverlayView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func linkPreviewButtonPressed(_ sender: LinkPreviewButton) {
|
@objc private func statusCardControlPressed(_ sender: StatusCardControl) {
|
||||||
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
|
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
|
||||||
guard let url = viewModel.card?.url else { return }
|
guard let url = viewModel.card?.url else { return }
|
||||||
delegate?.statusView(self, didTapCardWithURL: url)
|
delegate?.statusView(self, didTapCardWithURL: url)
|
||||||
|
@ -386,7 +383,7 @@ extension StatusView.Style {
|
||||||
statusView.authorAdaptiveMarginContainerView.margin = StatusView.containerLayoutMargin
|
statusView.authorAdaptiveMarginContainerView.margin = StatusView.containerLayoutMargin
|
||||||
statusView.containerStackView.addArrangedSubview(statusView.authorAdaptiveMarginContainerView)
|
statusView.containerStackView.addArrangedSubview(statusView.authorAdaptiveMarginContainerView)
|
||||||
|
|
||||||
// content container: V - [ contentMetaText ]
|
// content container: V - [ contentMetaText statusCardControl ]
|
||||||
statusView.contentContainer.axis = .vertical
|
statusView.contentContainer.axis = .vertical
|
||||||
statusView.contentContainer.spacing = 12
|
statusView.contentContainer.spacing = 12
|
||||||
statusView.contentContainer.distribution = .fill
|
statusView.contentContainer.distribution = .fill
|
||||||
|
@ -400,7 +397,7 @@ extension StatusView.Style {
|
||||||
|
|
||||||
// status content
|
// status content
|
||||||
statusView.contentContainer.addArrangedSubview(statusView.contentMetaText.textView)
|
statusView.contentContainer.addArrangedSubview(statusView.contentMetaText.textView)
|
||||||
statusView.contentContainer.addArrangedSubview(statusView.linkPreviewButton)
|
statusView.contentContainer.addArrangedSubview(statusView.statusCardControl)
|
||||||
|
|
||||||
statusView.spoilerOverlayView.translatesAutoresizingMaskIntoConstraints = false
|
statusView.spoilerOverlayView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
statusView.containerStackView.addSubview(statusView.spoilerOverlayView)
|
statusView.containerStackView.addSubview(statusView.spoilerOverlayView)
|
||||||
|
@ -542,8 +539,8 @@ extension StatusView {
|
||||||
filterHintLabel.isHidden = !isDisplay
|
filterHintLabel.isHidden = !isDisplay
|
||||||
}
|
}
|
||||||
|
|
||||||
func setLinkPreviewButtonDisplay(isDisplay: Bool = true) {
|
func setStatusCardControlDisplay(isDisplay: Bool = true) {
|
||||||
linkPreviewButton.isHidden = !isDisplay
|
statusCardControl.isHidden = !isDisplay
|
||||||
}
|
}
|
||||||
|
|
||||||
// container width
|
// container width
|
||||||
|
|
Loading…
Reference in New Issue