VoiceOver: improve description of gap cell, add actions to specify direction

This commit is contained in:
Shadowfacts 2022-12-05 18:43:32 -05:00
parent 0dcb7e71c4
commit 40ff8d0a2a
3 changed files with 45 additions and 1 deletions

View File

@ -15,6 +15,8 @@ class TimelineGapCollectionViewCell: UICollectionViewCell {
private let indicator = UIActivityIndicatorView(style: .medium)
private let chevronView = AnimatingChevronView()
var fillGap: ((TimelineGapDirection) async -> Void)?
override var isHighlighted: Bool {
didSet {
backgroundColor = isHighlighted ? .systemFill : .systemGroupedBackground
@ -100,6 +102,36 @@ class TimelineGapCollectionViewCell: UICollectionViewCell {
}
}
// MARK: Accessibility
override var isAccessibilityElement: Bool {
get { true }
set {}
}
override var accessibilityLabel: String? {
get {
"Load \(direction.accessibilityLabel)"
}
set {}
}
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
[TimelineGapDirection.below, .above].map { dir in
UIAccessibilityCustomAction(name: "Load \(dir.accessibilityLabel)") { [unowned self] _ in
Task {
showsIndicator = true
await fillGap?(dir)
showsIndicator = false
}
return true
}
}
}
set {}
}
}
private class AnimatingChevronView: UIView {

View File

@ -137,8 +137,11 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
}
let zeroHeightCell = UICollectionView.CellRegistration<ZeroHeightCollectionViewCell, Void> { _, _, _ in
}
let gapCell = UICollectionView.CellRegistration<TimelineGapCollectionViewCell, Void> { cell, indexPath, _ in
let gapCell = UICollectionView.CellRegistration<TimelineGapCollectionViewCell, Void> { [unowned self] cell, indexPath, _ in
cell.showsIndicator = false
cell.fillGap = { [unowned self] direction in
await self.controller.fillGap(in: direction)
}
}
let timelineDescriptionCell = UICollectionView.CellRegistration<PublicTimelineDescriptionCollectionViewCell, Item> { [unowned self] cell, indexPath, item in
guard case .public(let local) = timeline else {

View File

@ -379,4 +379,13 @@ enum TimelineGapDirection {
case below
/// Fill in above the gap. I.e., statuses that are immediately older than the status above the gap.
case above
var accessibilityLabel: String {
switch self {
case .below:
return "Newer"
case .above:
return "Older"
}
}
}