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