Add accessibility actions for links/mentions/hashtags in posts
This commit is contained in:
parent
505ca804b3
commit
1ce756a849
@ -99,6 +99,10 @@ extension StatusTableViewCell {
|
||||
return true
|
||||
}
|
||||
|
||||
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
|
||||
get { statusView.accessibilityCustomActions }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AdaptiveContainerMarginTableViewCell
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// MetaEntity+Accessibility.swift
|
||||
//
|
||||
//
|
||||
// Created by Jed Fox on 2022-11-03.
|
||||
//
|
||||
|
||||
import Meta
|
||||
|
||||
extension Meta.Entity {
|
||||
var accessibilityCustomActionLabel: String? {
|
||||
switch meta {
|
||||
case .url(_, trimmed: _, url: let url, userInfo: _):
|
||||
return "Link: \(url)"
|
||||
case .hashtag(_, hashtag: let hashtag, userInfo: _):
|
||||
return "Hashtag \(hashtag)"
|
||||
case .mention(_, mention: let mention, userInfo: _):
|
||||
return "Show Profile: @\(mention)"
|
||||
case .email(let email, userInfo: _):
|
||||
return "Email address: \(email)"
|
||||
// emoji are not actionable
|
||||
case .emoji:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
@ -315,7 +315,6 @@ extension StatusView.ViewModel {
|
||||
statusView.contentMetaText.configure(
|
||||
content: content
|
||||
)
|
||||
statusView.contentMetaText.textView.accessibilityLabel = content.string
|
||||
statusView.contentMetaText.textView.accessibilityTraits = [.staticText]
|
||||
statusView.contentMetaText.textView.accessibilityElementsHidden = false
|
||||
} else {
|
||||
@ -727,8 +726,23 @@ extension StatusView.ViewModel {
|
||||
statusView.accessibilityLabel = accessibilityLabel
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
Publishers.CombineLatest(
|
||||
$content,
|
||||
$isContentReveal.removeDuplicates()
|
||||
)
|
||||
.map { content, isRevealed in
|
||||
guard isRevealed, let entities = content?.entities else { return [] }
|
||||
return entities.compactMap { entity in
|
||||
guard let name = entity.accessibilityCustomActionLabel else { return nil }
|
||||
return UIAccessibilityCustomAction(name: name) { action in
|
||||
statusView.delegate?.statusView(statusView, metaText: statusView.contentMetaText, didSelectMeta: entity.meta)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
.assign(to: \.accessibilityCustomActions, on: statusView.contentMetaText.textView)
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -547,6 +547,13 @@ extension StatusView {
|
||||
|
||||
}
|
||||
|
||||
extension StatusView {
|
||||
public override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
|
||||
get { contentMetaText.textView.accessibilityCustomActions }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AdaptiveContainerView
|
||||
extension StatusView: AdaptiveContainerView {
|
||||
public func updateContainerViewComponentsLayoutMarginsRelativeArrangementBehavior(isEnabled: Bool) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user