Move VoiceOver Jump to Present action to timeline pages segmented control

This commit is contained in:
Shadowfacts 2022-12-05 17:13:45 -05:00
parent 0ce57d1308
commit eac2a9b19f
2 changed files with 19 additions and 15 deletions

View File

@ -114,19 +114,6 @@ 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)
} }
@ -418,7 +405,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
} }
} }
private func checkPresent(jumpImmediately: Bool) async { 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(),
!presentItems.isEmpty { !presentItems.isEmpty {
@ -426,7 +413,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>() var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
snapshot.appendSections([.statuses]) snapshot.appendSections([.statuses])
snapshot.appendItems(presentItems.map { .status(id: $0, collapseState: .unknown, filterState: .unknown) }, toSection: .statuses) snapshot.appendItems(presentItems.map { .status(id: $0, collapseState: .unknown, filterState: .unknown) }, toSection: .statuses)
dataSource.apply(snapshot, animatingDifferences: true) { dataSource.apply(snapshot, animatingDifferences: false) {
self.collectionView.scrollToItem(at: IndexPath(row: 0, section: 0), at: .top, animated: false)
UIAccessibility.post(notification: .screenChanged, argument: self.collectionView.cellForItem(at: IndexPath(row: 0, section: 0))) UIAccessibility.post(notification: .screenChanged, argument: self.collectionView.cellForItem(at: IndexPath(row: 0, section: 0)))
} }
} else { } else {

View File

@ -45,6 +45,22 @@ class TimelinesPageViewController: SegmentedPageViewController {
let filtersItem = UIBarButtonItem(image: UIImage(systemName: "line.3.horizontal.decrease.circle"), style: .plain, target: self, action: #selector(filtersPressed)) let filtersItem = UIBarButtonItem(image: UIImage(systemName: "line.3.horizontal.decrease.circle"), style: .plain, target: self, action: #selector(filtersPressed))
filtersItem.accessibilityLabel = "Filters" filtersItem.accessibilityLabel = "Filters"
navigationItem.leftBarButtonItem = filtersItem navigationItem.leftBarButtonItem = filtersItem
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))
segmentedControl.accessibilityCustomActions = [
UIAccessibilityCustomAction(attributedName: jumpToPresentName, actionHandler: { [unowned self] _ in
guard let vc = pageControllers[currentIndex] as? TimelineViewController else {
return false
}
Task {
await vc.checkPresent(jumpImmediately: true)
}
return true
})
]
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {