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

[ASDisplayNode] Implement accessibilityViewIsModal #1858

Merged
merged 5 commits into from
Jun 1, 2020

Conversation

rcancro
Copy link
Contributor

@rcancro rcancro commented May 28, 2020

A PR to add support for accessibilityViewIsModal in CollectAccessibilityElements.

If in a list of subnodes more than 1 subnode has accessibilityViewIsModal marked as YES, then the node with the highest index in subnodes will be the one that is considered modal. This behavior matches UIKit.

If the value of accessibilityViewIsModal changes, we need to clear all the cached accessibilityElements from that view up. I added this in ASDisplayNode’s setAccessibilityViewIsModal method. Note that if we ship ASExperimentalDoNotCacheAccessibilityElements then we can remove the invalidation step.

Finally, I changed all the tests to ask the view for accessibilityElements, not the node. This is a better representation of what will really happen when UIKit asks a node’s view for its accessibility elements. It also allowed me to test that clearing the accessibilityElements was working.

A PR to add support for `accessibilityViewIsModal` in `CollectAccessibilityElements`.

If in a list of subnodes more than 1 subnode has `accessibilityViewIsModal` marked as `YES`, then the node with the highest index in `subnodes` will be the one that is considered modal. This behavior matches UIKit.

If the value of `accessibilityViewIsModal` changes, we need to clear all the cached `accessibilityElements` from that view up. I added this in ASDisplayNode’s `setAccessibilityViewIsModal` method. Note that if we ship `ASExperimentalDoNotCacheAccessibilityElements` then we can remove the invalidation step.

Finally, I changed all the tests to ask the view for accessibilityElements, not the node. This is a better representation of what will really happen when UIKit asks a node’s view for its accessibility elements. It also allowed me to test that clearing the accessibilityElements was working.
Source/Private/ASDisplayNode+UIViewBridge.mm Outdated Show resolved Hide resolved
@@ -280,7 +294,7 @@ static void CollectAccessibilityElements(ASDisplayNode *node, NSMutableArray *el
} else if (subnode.isLayerBacked) {
// Go down the hierarchy of the layer backed subnode and collect all of the UIAccessibilityElement
CollectUIAccessibilityElementsForNode(subnode, node, view, elements);
} else if (subnode.accessibilityElementCount > 0) {
} else if (subnode.accessibilityElements.count > 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does anyone have any thoughts around this change? When I made an example app with accessibilityViewIsModal set to YES accessibilityElementCount was 1 when I turned on voice over. However, in the tests it was always 0.

I'm not really sure where/how accessibilityElementCount is being changed in my test app. It isn't a property on NSObject, but a method that should be overwritten (which we aren't doing). This comment also exists in the header of _ASDisplayViewAccessiblity.h, so I'm not sure why we are favoring accessibilityElementCount over accessibilityElements:

// WARNING: When dealing with accessibility elements, please use the `accessibilityElements`
// property instead of the older methods e.g. `accessibilityElementCount()`. While the older methods
// should still work as long as accessibility is enabled, this framework provides no guarantees on
// their correctness.

Copy link
Contributor

@vovasty vovasty May 29, 2020

Choose a reason for hiding this comment

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

as far as I understand we should rely on accessibilityElementCount, but
according to documentation it returns 0 by default. May be default implementation?

- (NSInteger)accessibilityElementCount {
  return [[self accessibilityElements] count];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just played with this some more, and it doesn't work. I'll focus on a way to make the tests pass and revert this change.

@rcancro rcancro merged commit 08bd6f6 into TextureGroup:master Jun 1, 2020
piotrdebosz pushed a commit to getstoryteller/Texture that referenced this pull request Mar 1, 2021
* [ASDisplayNode] Implement accessibilityViewIsModal

A PR to add support for `accessibilityViewIsModal` in `CollectAccessibilityElements`.

If in a list of subnodes more than 1 subnode has `accessibilityViewIsModal` marked as `YES`, then the node with the highest index in `subnodes` will be the one that is considered modal. This behavior matches UIKit.

If the value of `accessibilityViewIsModal` changes, we need to clear all the cached `accessibilityElements` from that view up. I added this in ASDisplayNode’s `setAccessibilityViewIsModal` method. Note that if we ship `ASExperimentalDoNotCacheAccessibilityElements` then we can remove the invalidation step.

Finally, I changed all the tests to ask the view for accessibilityElements, not the node. This is a better representation of what will really happen when UIKit asks a node’s view for its accessibility elements. It also allowed me to test that clearing the accessibilityElements was working.

* add some experiment checks

* fix tests and address jon’s comment

* Fix tests

* remove debug code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants