-
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
Support setting accessibilityElements
#1488
Support setting accessibilityElements
#1488
Conversation
9d0ba2d
to
22f016e
Compare
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.
Thanks for submitting the diff, @raycsh017.
Do you think the API will be more extensible if we just declare -[ASDisplayNode accessibilityElements]
in a public interface and thus make it open for overriding? Clients then can have their own custom array to return everytime, or modify the array returned by [super accessibilityElements]
.
@@ -257,6 +258,7 @@ - (void)setAccessibilityElements:(NSArray *)accessibilityElements | |||
{ | |||
ASDisplayNodeAssertMainThread(); | |||
_accessibilityElements = nil; |
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.
It's odd that this setter doesn't consider the provided param and always sets the ivar to nil. We probably should rename it to resetAccessibilityElements
or clearAccessibilityElements
?
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.
Yeah that sounds good, I wasn't sure if this was intended or we just haven't had a chance to implement this portion yet :/
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 think setting the provided param to _accessibilityElements
is the right way to do.
@maicki: thoughts?
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.
Also, if the _accessibilityElements
ivar is updated here, we may not even need a new _customAccessibilityElements
ivar because setting a non-nil array here will cause the setter to return it (i.e it won't call [viewNode accessibilityElements]
.
@nguyenhuy Also, it could be somewhat problematic if you want to set |
@@ -257,6 +258,7 @@ - (void)setAccessibilityElements:(NSArray *)accessibilityElements | |||
{ | |||
ASDisplayNodeAssertMainThread(); | |||
_accessibilityElements = nil; |
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 think setting the provided param to _accessibilityElements
is the right way to do.
@maicki: thoughts?
@@ -257,6 +258,7 @@ - (void)setAccessibilityElements:(NSArray *)accessibilityElements | |||
{ | |||
ASDisplayNodeAssertMainThread(); | |||
_accessibilityElements = nil; |
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.
Also, if the _accessibilityElements
ivar is updated here, we may not even need a new _customAccessibilityElements
ivar because setting a non-nil array here will cause the setter to return it (i.e it won't call [viewNode accessibilityElements]
.
ee67370
to
f263f4b
Compare
if (_accessibilityElements == nil || ASActivateExperimentalFeature(ASExperimentalDisableAccessibilityCache)) { | ||
_accessibilityElements = [viewNode accessibilityElements]; | ||
return [viewNode accessibilityElements]; |
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.
This might be the necessary evil (in that we don't cache it and return that next time) if we want to limit the accessibilityElements
storage to one for either the custom or Texture-defined a11y elements (ie. items returned with current behavior) as opposed to two. It was hard to keep track of whether the ivar contains custom a11y elements or the default especially if you consider the case where you might be dynamically adding/removing subnodes and so you need to update the a11y elements returned for a node. Fwiw, I think another benefit to this method might be the accuracy of the list of items returned from accessibilityElements
.
f263f4b
to
187108b
Compare
Made changes to allow modification of |
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.
Overall, LGTM. I'll approve after a fix in the block setter. Would be great if there is another approval from @maicki.
Source/ASDisplayNode.mm
Outdated
- (void)setAccessibilityElementsBlock:(ASDisplayNodeAccessibilityElementsBlock)accessibilityElementsBlock | ||
{ | ||
MutexLocker l(__instanceLock__); | ||
_accessibilityElementsBlock = accessibilityElementsBlock; |
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.
You probbaly want to store a copy of the provided block.
|
||
if (_accessibilityElementsBlock) { | ||
NSArray *accessibilityElementsCopy = [accessibilityElements copy]; | ||
accessibilityElements = _accessibilityElementsBlock(accessibilityElementsCopy); |
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'm wondering if it's ok to give the block a mutable array, so that the block may modify it directly and we don't need to copy it beforehand?
I'm not sure if it's a good API design?
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.
That would work too, I just felt this might be safer, sort of forcing people to create their own mutable array and add the object as needed and return a copy of it. Do we have an example of supporting custom blocks like this? it would be nice to follow an existing pattern too if there is one.
Sometimes we want to override `accessibilityElements` so that we can skip over elements unnecessary for interacting with the app using VoiceOver or limit the interaction to child viewcontrollers presented, etc. For this purpose, this commit introduces `accessibilityElementsBlock` that receives the default `accessibilityElements` as input and modifies the elements returned. If not set, `accessibilityElements` should still return the elements found from the node hierarchy.
b8e1548
to
2303d1d
Compare
My impression is that this diff is blocked/replaced by #1525 (please correct me if I'm wrong, I've lost the context regarding this area and would need to spend some time to reload). With that, I'm gonna close this PR. Feel free to reopen it if need to. Thanks all. |
Sometimes we want to override
accessibilityElements
so that we canskip over elements unnecessary for interacting with the app using VoiceOver
or limit the interaction to child viewcontrollers presented, etc.
For this purpose, this commit adds support for setting custom
accessibilityElements
. If not set,accessibilityElements
should stillreturn the elements found from the view/layer hierarchy.