From 78675a3c4c1a69a6163ea747c9c8b0d4a471c9aa Mon Sep 17 00:00:00 2001 From: Josh Heald Date: Fri, 14 Jan 2022 06:28:10 +0000 Subject: [PATCH] 17760 Prevent calendar scrollback in VoiceOver Previously, when moving VoiceOver focus from the next button to the Date Cells on the Schedule Post popover, the calendar would scroll back to 1 Jan 1951. This automated scrollback is a probably-intentional part of UICollectionView (to enable VoiceOver to read everything in a collection view) but it is not appropriate in its use here as a calendar. This change prevents that automated scrollback, and only makes any change when the relevant accessibility features are in use. The same issue happened sporadically on the year view calendar; I wasn't able to find repro steps for that, but this change should improve the behaviour there as well. --- RELEASE-NOTES.txt | 2 +- .../Scheduling/CalendarCollectionView.swift | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 97fcd08f3f00..06bc4457ae37 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,7 +1,7 @@ 19.1 ----- * [*] Signup: Fixed bug where username selection screen could be pushed twice. [#17624] -* [**] Accessibility: VoiceOver improvements on Activity Log and Schedule Post calendars [#17756] +* [**] Accessibility: VoiceOver improvements on Activity Log and Schedule Post calendars [#17756, #17761] 19.0 ----- diff --git a/WordPress/Classes/ViewRelated/Post/Scheduling/CalendarCollectionView.swift b/WordPress/Classes/ViewRelated/Post/Scheduling/CalendarCollectionView.swift index dc349815f3e6..5987e81ed8e6 100644 --- a/WordPress/Classes/ViewRelated/Post/Scheduling/CalendarCollectionView.swift +++ b/WordPress/Classes/ViewRelated/Post/Scheduling/CalendarCollectionView.swift @@ -67,6 +67,33 @@ class CalendarCollectionView: WPJTACMonthView { calendarDataSource = calDataSource calendarDelegate = calDataSource } + + /// VoiceOver scrollback workaround + /// When using VoiceOver, moving focus from the surrounding elements (usually the next month button) to the calendar DateCells, a + /// scrollback to 0 was triggered by the system. This appears to be expected (though irritating) behaviour with a paging UICollectionView. + /// The impact of this scrollback for the month view calendar (as used to schedule a post) is that the calendar jumps to 1951-01-01, with + /// the only way to navigate forwards being to tap the "next month" button repeatedly. + /// Ignoring these scrolls back to 0 when VoiceOver is in use prevents this issue, while not impacting other use of the calendar. + /// Similar behaviour sometimes occurs with the non-paging year view calendar (as used for activity log filtering) which is harder to reproduce, + /// but also remedied by this change. + override func setContentOffset(_ contentOffset: CGPoint, animated: Bool) { + if shouldPreventAccessibilityFocusScrollback(for: contentOffset) { + return + } + super.setContentOffset(contentOffset, animated: animated) + } + + func shouldPreventAccessibilityFocusScrollback(for newContentOffset: CGPoint) -> Bool { + if UIAccessibility.isVoiceOverRunning { + switch style { + case .month: + return newContentOffset.x == 0 && contentOffset.x > 0 + case .year: + return newContentOffset.y == 0 && contentOffset.y > 0 + } + } + return false + } } class CalendarDataSource: JTACMonthViewDataSource {