Status VoiceOver improvements

Closes #229
Closes #230
This commit is contained in:
Shadowfacts 2022-11-12 15:04:44 -05:00
parent 3fd62552b3
commit 7294ff6e1a
2 changed files with 84 additions and 20 deletions

View File

@ -321,32 +321,67 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
// MARK: Accessibility // MARK: Accessibility
override var accessibilityLabel: String? { override var isAccessibilityElement: Bool {
get { true }
set {}
}
override var accessibilityAttributedLabel: NSAttributedString? {
get { get {
guard let status = mastodonController.persistentContainer.status(for: statusID) else { guard let status = mastodonController.persistentContainer.status(for: statusID) else {
return nil return nil
} }
var str = "\(status.account.displayOrUserName), \(contentTextView.text ?? "")" var str = AttributedString("\(status.account.displayOrUserName), ")
if statusState.collapsed ?? false {
if !status.spoilerText.isEmpty {
str += AttributedString(status.spoilerText)
str += ", "
}
str += "collapsed"
} else {
str += AttributedString(contentTextView.attributedText)
}
if status.attachments.count > 0 { if status.attachments.count > 0 {
// TODO: localize me // TODO: localize me
str += ", \(status.attachments.count) attachment\(status.attachments.count > 1 ? "s" : "")" str += AttributedString(", \(status.attachments.count) attachment\(status.attachments.count > 1 ? "s" : "")")
} }
if status.poll != nil { if status.poll != nil {
str += ", poll" str += ", poll"
} }
str += ", \(status.createdAt.formatted(.relative(presentation: .numeric)))" str += AttributedString(", \(status.createdAt.formatted(.relative(presentation: .numeric)))")
if status.visibility < .unlisted {
str += AttributedString(", \(status.visibility.displayName)")
}
if status.localOnly {
str += ", local"
}
if let rebloggerID, if let rebloggerID,
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
str += ", reblogged by \(reblogger.displayOrUserName)" str += AttributedString(", reblogged by \(reblogger.displayOrUserName)")
}
return NSAttributedString(str)
}
set {}
}
override var accessibilityHint: String? {
get {
if statusState.collapsed ?? false {
return "Double tap to expand the post."
} else {
return nil
} }
return str
} }
set {} set {}
} }
override func accessibilityActivate() -> Bool { override func accessibilityActivate() -> Bool {
delegate?.selected(status: statusID, state: statusState.copy()) if statusState.collapsed ?? false {
toggleCollapse()
} else {
delegate?.selected(status: statusID, state: statusState.copy())
}
return true return true
} }

View File

@ -249,33 +249,62 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
// MARK: - Accessibility // MARK: - Accessibility
override var accessibilityLabel: String? { override var accessibilityAttributedLabel: NSAttributedString? {
get { get {
guard let status = mastodonController.persistentContainer.status(for: statusID) else { guard let status = mastodonController.persistentContainer.status(for: statusID) else {
return nil return nil
} }
var str = "\(status.account.displayName), \(contentTextView.text ?? "")" var str = AttributedString("\(status.account.displayOrUserName), ")
if statusState.collapsed ?? false {
if !status.spoilerText.isEmpty {
str += AttributedString(status.spoilerText)
str += ", "
}
str += "collapsed"
} else {
str += AttributedString(contentTextView.attributedText)
}
if status.attachments.count > 0 { if status.attachments.count > 0 {
// todo: localize me // TODO: localize me
str += ", \(status.attachments.count) attachments" str += AttributedString(", \(status.attachments.count) attachment\(status.attachments.count > 1 ? "s" : "")")
} }
if status.poll != nil { if status.poll != nil {
str += ", poll" str += ", poll"
} }
str += ", \(TimelineStatusTableViewCell.relativeDateFormatter.localizedString(for: status.createdAt, relativeTo: Date()))" str += AttributedString(", \(status.createdAt.formatted(.relative(presentation: .numeric)))")
if let rebloggerID = rebloggerID, if status.visibility < .unlisted {
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { str += AttributedString(", \(status.visibility.displayName)")
str += ", reblogged by \(reblogger.displayName)" }
if status.localOnly {
str += ", local"
}
if let rebloggerID,
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
str += AttributedString(", reblogged by \(reblogger.displayOrUserName)")
}
return NSAttributedString(str)
}
set {}
}
override var accessibilityHint: String? {
get {
if statusState.collapsed ?? false {
return "Double tap to expand the post."
} else {
return nil
} }
return str
} }
set {} set {}
} }
override func accessibilityActivate() -> Bool { override func accessibilityActivate() -> Bool {
didSelectCell() if statusState.collapsed ?? false {
collapseButtonPressed()
} else {
didSelectCell()
}
return true return true
} }