-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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.
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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];
}
There was a problem hiding this comment.
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.
* [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
A PR to add support for
accessibilityViewIsModal
inCollectAccessibilityElements
.If in a list of subnodes more than 1 subnode has
accessibilityViewIsModal
marked asYES
, then the node with the highest index insubnodes
will be the one that is considered modal. This behavior matches UIKit.If the value of
accessibilityViewIsModal
changes, we need to clear all the cachedaccessibilityElements
from that view up. I added this in ASDisplayNode’ssetAccessibilityViewIsModal
method. Note that if we shipASExperimentalDoNotCacheAccessibilityElements
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.