Merge pull request #923 from j-f1/profile-about-a11y

IOS-76: Improve accessibility of the About fields on profiles
This commit is contained in:
Marcus Kida 2023-02-08 11:05:38 +01:00 committed by GitHub
commit d7c9b1ded7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 9 deletions

View File

@ -92,13 +92,18 @@ extension ProfileFieldSection {
formatter.dateStyle = .medium
formatter.timeStyle = .short
let dateString = formatter.string(from: verifiedAt)
cell.checkmark.accessibilityLabel = L10n.Scene.Profile.Fields.Verified.long(dateString)
let longLabel = L10n.Scene.Profile.Fields.Verified.long(dateString)
cell.checkmark.accessibilityLabel = longLabel
cell.accessibilityValue = "\(cell.valueMetaLabel.backedString), \(longLabel)"
cell.checkmarkPopoverString = L10n.Scene.Profile.Fields.Verified.short(dateString)
} else {
cell.checkmark.isHidden = true
cell.checkmarkPopoverString = nil
cell.accessibilityValue = cell.valueMetaLabel.backedString
}
cell.accessibilityLabel = cell.keyMetaLabel.backedString
cell.delegate = configuration.profileFieldCollectionViewCellDelegate
}

View File

@ -13,7 +13,7 @@ import MastodonAsset
import MastodonLocalization
protocol ProfileFieldCollectionViewCellDelegate: AnyObject {
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, metaLebel: MetaLabel, didSelectMeta meta: Meta)
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, metaLabel: MetaLabel, didSelectMeta meta: Meta)
}
final class ProfileFieldCollectionViewCell: UICollectionViewCell {
@ -107,6 +107,8 @@ extension ProfileFieldCollectionViewCell {
keyMetaLabel.linkDelegate = self
valueMetaLabel.linkDelegate = self
isAccessibilityElement = true
}
@objc public func didTapCheckmark(_ recognizer: UITapGestureRecognizer) {
@ -127,6 +129,40 @@ extension ProfileFieldCollectionViewCell {
UIMenuController.shared.showMenu(from: checkmark, rect: checkmark.bounds)
}
}
private var valueMetas: [(title: String, Meta)] {
var result: [(title: String, Meta)] = []
valueMetaLabel.textStorage.enumerateAttribute(NSAttributedString.Key("MetaAttributeKey.meta"), in: NSMakeRange(0, valueMetaLabel.textStorage.length)) { value, range, _ in
if let value = value as? Meta {
result.append((valueMetaLabel.textStorage.string.substring(with: range), value))
}
}
return result
}
override func accessibilityActivate() -> Bool {
if let (_, meta) = valueMetas.first {
delegate?.profileFieldCollectionViewCell(self, metaLabel: valueMetaLabel, didSelectMeta: meta)
return true
}
return false
}
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
let valueMetas = valueMetas
if valueMetas.count < 2 { return nil }
return valueMetas.compactMap { title, meta in
guard let name = meta.accessibilityLabel else { return nil }
return UIAccessibilityCustomAction(name: name) { [weak self] _ in
guard let self, let delegate = self.delegate else { return false }
delegate.profileFieldCollectionViewCell(self, metaLabel: self.valueMetaLabel, didSelectMeta: meta)
return true
}
}
}
set {}
}
}
// UIMenuController boilerplate
@ -151,7 +187,7 @@ extension ProfileFieldCollectionViewCell {
extension ProfileFieldCollectionViewCell: MetaLabelDelegate {
func metaLabel(_ metaLabel: MetaLabel, didSelectMeta meta: Meta) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
delegate?.profileFieldCollectionViewCell(self, metaLebel: metaLabel, didSelectMeta: meta)
delegate?.profileFieldCollectionViewCell(self, metaLabel: metaLabel, didSelectMeta: meta)
}
}

View File

@ -144,8 +144,8 @@ extension ProfileAboutViewController: UICollectionViewDelegate {
// MARK: - ProfileFieldCollectionViewCellDelegate
extension ProfileAboutViewController: ProfileFieldCollectionViewCellDelegate {
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, metaLebel: MetaLabel, didSelectMeta meta: Meta) {
delegate?.profileAboutViewController(self, profileFieldCollectionViewCell: cell, metaLabel: metaLebel, didSelectMeta: meta)
func profileFieldCollectionViewCell(_ cell: ProfileFieldCollectionViewCell, metaLabel: MetaLabel, didSelectMeta meta: Meta) {
delegate?.profileAboutViewController(self, profileFieldCollectionViewCell: cell, metaLabel: metaLabel, didSelectMeta: meta)
}
}

View File

@ -8,9 +8,9 @@
import Meta
import MastodonLocalization
extension Meta.Entity {
var accessibilityCustomActionLabel: String? {
switch meta {
extension Meta {
public var accessibilityLabel: String? {
switch self {
case .url(_, trimmed: _, url: let url, userInfo: _):
return L10n.Common.Controls.Status.MetaEntity.url(url)
case .hashtag(_, hashtag: let hashtag, userInfo: _):

View File

@ -889,7 +889,7 @@ extension StatusView.ViewModel {
.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 }
guard let name = entity.meta.accessibilityLabel else { return nil }
return UIAccessibilityCustomAction(name: name) { action in
statusView.delegate?.statusView(statusView, metaText: statusView.contentMetaText, didSelectMeta: entity.meta)
return true