forked from zelo72/mastodon-ios
feat: add ProfileCardView a11y supports
This commit is contained in:
parent
80fe24ed22
commit
64640edd2b
|
@ -42,6 +42,8 @@ extension ProfileCardView {
|
|||
@Published public var isBlocking = false
|
||||
@Published public var isBlockedBy = false
|
||||
|
||||
@Published public var groupedAccessibilityLabel = ""
|
||||
|
||||
init() {
|
||||
backgroundColor = ThemeService.shared.currentTheme.value.systemBackgroundColor
|
||||
Publishers.CombineLatest(
|
||||
|
@ -75,6 +77,7 @@ extension ProfileCardView.ViewModel {
|
|||
bindBio(view: view)
|
||||
bindRelationship(view: view)
|
||||
bindDashboard(view: view)
|
||||
bindAccessibility(view: view)
|
||||
}
|
||||
|
||||
private func bindAppearacne(view: ProfileCardView) {
|
||||
|
@ -185,4 +188,27 @@ extension ProfileCardView.ViewModel {
|
|||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
|
||||
private func bindAccessibility(view: ProfileCardView) {
|
||||
let authorAccessibilityLabel = Publishers.CombineLatest(
|
||||
$authorName,
|
||||
$bioContent
|
||||
)
|
||||
.map { authorName, bioContent -> String? in
|
||||
var strings: [String?] = []
|
||||
strings.append(authorName?.string)
|
||||
strings.append(bioContent?.string)
|
||||
return strings.compactMap { $0 }.joined(separator: ", ")
|
||||
}
|
||||
|
||||
authorAccessibilityLabel
|
||||
.map { $0 ?? "" }
|
||||
.assign(to: &$groupedAccessibilityLabel)
|
||||
|
||||
$groupedAccessibilityLabel
|
||||
.sink { accessibilityLabel in
|
||||
view.accessibilityLabel = accessibilityLabel
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,6 +204,8 @@ extension ProfileCardView {
|
|||
let bioMetaTextAdaptiveMarginContainerView = AdaptiveMarginContainerView()
|
||||
bioMetaTextAdaptiveMarginContainerView.contentView = bioMetaText.textView
|
||||
bioMetaTextAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
|
||||
bioMetaText.textView.setContentHuggingPriority(.required - 1, for: .vertical)
|
||||
bioMetaText.textView.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
||||
container.addArrangedSubview(bioMetaTextAdaptiveMarginContainerView)
|
||||
container.setCustomSpacing(16, after: bioMetaTextAdaptiveMarginContainerView)
|
||||
|
||||
|
@ -218,6 +220,7 @@ extension ProfileCardView {
|
|||
infoContainer.addArrangedSubview(UIView())
|
||||
let relationshipActionButtonShadowContainer = ShadowBackgroundContainer()
|
||||
infoContainer.addArrangedSubview(relationshipActionButtonShadowContainer)
|
||||
updateInfoContainerLayout()
|
||||
|
||||
relationshipActionButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
relationshipActionButtonShadowContainer.addSubview(relationshipActionButton)
|
||||
|
@ -227,7 +230,7 @@ extension ProfileCardView {
|
|||
relationshipActionButton.trailingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.trailingAnchor),
|
||||
relationshipActionButton.bottomAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.bottomAnchor),
|
||||
relationshipActionButton.widthAnchor.constraint(greaterThanOrEqualToConstant: ProfileCardView.friendshipActionButtonSize.width).priority(.required - 1),
|
||||
relationshipActionButton.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 10),
|
||||
relationshipActionButton.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 2),
|
||||
])
|
||||
|
||||
let bottomPadding = UIView()
|
||||
|
@ -247,12 +250,17 @@ extension ProfileCardView {
|
|||
}
|
||||
|
||||
public override func layoutSubviews() {
|
||||
updateInfoContainerLayout()
|
||||
super.layoutSubviews()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ProfileCardView {
|
||||
private func updateInfoContainerLayout() {
|
||||
let isCompactAdaptive = bounds.width < 350
|
||||
infoContainer.axis = isCompactAdaptive ? .vertical : .horizontal
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ProfileCardView {
|
||||
|
|
|
@ -70,6 +70,12 @@ extension ProfileCardTableViewCell {
|
|||
])
|
||||
|
||||
profileCardView.delegate = self
|
||||
|
||||
profileCardView.isAccessibilityElement = true
|
||||
accessibilityElements = [
|
||||
profileCardView,
|
||||
profileCardView.relationshipActionButton
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue