Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and improve accessibility implementation #284

Merged
merged 3 commits into from
Nov 28, 2023

Conversation

bryankeller
Copy link
Contributor

Details

This simplifies and also improves support for Voice Over. Previously, we had the concept of on-screen accessibility elements, and some special off-screen accessibility elements that we used to make off-screen content focusable by Voice Over to prevent the dreaded "heading not found" issue that happens with lazy views like this and UICollectionView.

That approach had some issues with SwiftUI views, since it made some assumptions about the off-screen accessibility element being based on a UIView.

I rethought things a bit, and realized we could simplify. I had recently added support for doing an extended bounds layout pass, which forces off-screen views to be created and laid out for the purpose of having animations look better. We can reuse this code when Voice Over is running to ensure that nearby off-screen views can be focused. This change allows us to unify how all accessibility elements are treated, no longer needing to differentiate between off-screen and on-screen elements.

Related Issue

N/A

Motivation and Context

Fixes accessibility behavior for SwiftUI views

How Has This Been Tested

Example app

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller bryankeller added the bug Something isn't working label Nov 28, 2023
var cachedAccessibilityElements: [Any]?

override var contentInsetAdjustmentBehavior: ContentInsetAdjustmentBehavior {
didSet {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it safer to do get/set like we do below? wondering if we could get into loops more easily this way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is unchanged from before (just moved files), but I do remember testing that back in the day and it didn't work. It was necessary to call super.contentInsetAdjustmentBehavior to ensure it works properly.

@bryankeller bryankeller merged commit 8d3f745 into master Nov 28, 2023
3 checks passed
@bryankeller bryankeller deleted the bk/simplify-a11y branch November 28, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants