Add Jump to Present VoiceOver action

Closes #288
This commit is contained in:
Shadowfacts 2022-12-04 22:06:04 -05:00
parent 77ab2c3753
commit b64c748b73
1 changed files with 28 additions and 5 deletions

View File

@ -114,6 +114,19 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
self.reapplyFilters(actionsChanged: actionsChanged) self.reapplyFilters(actionsChanged: actionsChanged)
} }
let jumpToPresentName = NSMutableAttributedString("Jump to Present")
// otherwise it pronounces it as 'pɹizˈənt'
// its IPA is also bad, this should be an alveolar approximant not a trill
jumpToPresentName.addAttribute(.accessibilitySpeechIPANotation, value: "ˈprɛ.zənt", range: NSRange(location: "Jump to ".count, length: "Present".count))
accessibilityCustomActions = [
UIAccessibilityCustomAction(attributedName: jumpToPresentName, actionHandler: { [unowned self] _ in
Task {
await self.checkPresent(jumpImmediately: true)
}
return true
})
]
NotificationCenter.default.addObserver(self, selector: #selector(sceneWillEnterForeground), name: UIScene.willEnterForegroundNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(sceneWillEnterForeground), name: UIScene.willEnterForegroundNotification, object: nil)
} }
@ -192,7 +205,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
if case .notLoadedInitial = controller.state { if case .notLoadedInitial = controller.state {
if doRestore() { if doRestore() {
Task { Task {
await checkPresent() await checkPresent(jumpImmediately: false)
} }
} else { } else {
Task { Task {
@ -376,7 +389,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
return return
} }
Task { Task {
await checkPresent() await checkPresent(jumpImmediately: false)
} }
} }
@ -405,10 +418,20 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
} }
} }
private func checkPresent() async { private func checkPresent(jumpImmediately: Bool) async {
if case .idle = controller.state, if case .idle = controller.state,
let presentItems = try? await loadInitial() { let presentItems = try? await loadInitial(),
insertPresentItemsIfNecessary(presentItems) !presentItems.isEmpty {
if jumpImmediately {
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
snapshot.appendSections([.statuses])
snapshot.appendItems(presentItems.map { .status(id: $0, collapseState: .unknown, filterState: .unknown) }, toSection: .statuses)
dataSource.apply(snapshot, animatingDifferences: true) {
UIAccessibility.post(notification: .screenChanged, argument: self.collectionView.cellForItem(at: IndexPath(row: 0, section: 0)))
}
} else {
insertPresentItemsIfNecessary(presentItems)
}
} }
} }