Skip to content

Commit

Permalink
17760 Prevent calendar scrollback in VoiceOver
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshheald committed Jan 14, 2022
1 parent 3f1f131 commit 30b9ff3
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 30b9ff3

Please sign in to comment.