From eac2a9b19f0ef571971595b510391d1dbd651dd3 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 5 Dec 2022 17:13:45 -0500 Subject: [PATCH] Move VoiceOver Jump to Present action to timeline pages segmented control --- .../Timeline/TimelineViewController.swift | 18 +++--------------- .../Timeline/TimelinesPageViewController.swift | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 4fa3fa79..e7ff454f 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -114,19 +114,6 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro 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) } @@ -418,7 +405,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } } - private func checkPresent(jumpImmediately: Bool) async { + func checkPresent(jumpImmediately: Bool) async { if case .idle = controller.state, let presentItems = try? await loadInitial(), !presentItems.isEmpty { @@ -426,7 +413,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections([.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))) } } else { diff --git a/Tusker/Screens/Timeline/TimelinesPageViewController.swift b/Tusker/Screens/Timeline/TimelinesPageViewController.swift index 237edb14..89ab316c 100644 --- a/Tusker/Screens/Timeline/TimelinesPageViewController.swift +++ b/Tusker/Screens/Timeline/TimelinesPageViewController.swift @@ -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)) filtersItem.accessibilityLabel = "Filters" 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) {