TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.29k forks source link

CollectAccessibilityElementsForView doesn't look deep enough in hierarchy to make actual elements accessible #245

Open mlilek-nyt opened 7 years ago

mlilek-nyt commented 7 years ago

A certain node hierarchy in my app is inaccessible to VoiceOver and everything I've found doesn't actually allow me to make it accessible.

I have an ASViewController displaying an ASCollectionNode. We return an instance of MyCustomASCellNodeSubclass as a supplementary node for UICollectionElementKindSectionHeader. A subnode of this contains a native UISegmentedControl.

Our node hierarchy ends up as:

ASCollectionNode
   | MyCustomASCellNodeSubclass
   |    | MyCustomASDisplayNodeSubclass
   |    |    | ASDisplayNode
   |    |    |    | UISegmentedControl (Native, not a node)

And the resulting view hierarchy for the collection header:

<UICollectionReusableView>
   | <MyCustomASCellNodeSubclass-View>
   |    | <MyCustomASDisplayNodeSubclass-View>
   |    |    | <ASDisplayNode-View>
   |    |    |    | <UISegmentedControl>
   |    |    |    |    | <UISegment> (The actual accessibility elements I want exposed)

The issue is that when iOS's accessibility code walks the view hierarchy for accessibility elements, the UICollectionReusableView defers to the MyCustomASCellNodeSubclass-View. CollectAccessibilityElementsForView kicks in and starts collecting accessibility elements from MyCustomASDisplayNodeSubclass.

Because this node isn't layer backed, at best this function will add MyCustomASDisplayNodeSubclass-View as an accessibility element. But that view doesn't contain any accessibility elements. And because this function is only adding the view as an accessibility element and not asking the node itself for any accessibility elements (just asking either isAccessibilityElements or checking accessibilityElementCount), I can't hoist up the UISegmentedControl's accessibility elements.

Am I missing something here? Found this using 2.2, but is still an issue even after upgrading to 2.3.1. Not sure the easiest way to build a sample project, but hopefully this is enough information to allow someone to easily reproduce it. We're not doing anything special in our collection node and the two MyCustomFooSubclasses are pretty much just configuring the segmented control and specifying a layout spec.

Please let me know if there's any other info I can provide!

maicki commented 7 years ago

@mlilek-nyt Hey Matt - I tried to reproduce it and got some sample app up here:

TextureAccessibilityViewHierarchy.zip

I'm not pretty sure if this reflects the kind of the view hierarchy you have (I don't use a collection node, instead I just use a plain node for it. From the Xcode accessibility tool it seems all fine and it reaches down to the UISegmentedControl, but could you double check and I would appreciate if you tweak it so it would reflect more the state on your side.

Thanks!