Is there an equivalent accessibilityElement API for SwiftUI - specifically when making visualizations using the new Canvas view in SwiftUI

What's the most effective equivalent to the accessibilityElement API when you're creating visualizations in SwiftUI using the new Canvas drawing mechanism?

When I'm drawing with Canvas, I'd know the same roughly positioning information as drawing in UIKit or AppKit and making charts visualizations, but I didn't spot an equivalent API for marking sections of the visualization to be associated with specific values. (akin to setting the frame coordinates in a UIView accessibility element)

I've only just started playing with Canvas, so I may be wrong - but it seems like a monolithic style view element that I can't otherwise easily break down into sub-components like I can by applying separate CALayers or UIViews on which to hang accessibility indicators.

For making the equivalent bar chart in straight up SwiftUI, is there a similar mechanism, or is this a place where I'd need to pop the escape hatch to UIKit or AppKit and do the relevant work there, and then host it inside a SwiftUI view?

Replies

Take a look at the SwiftUI Accessibility: Beyond The Basics WWDC 2021 session

This session is what prompted this question - The canvas is a single element, and I want to have multiple accessibility elements that I'm displaying within it. That may not be (yet?) possible, but I wanted to see if there was any suggestions for a pattern of how to create multiple children and align them with specific in-view-coordinate spaces, which mimics a bit of what you can do within UIKit where you specify a frame location for a child accessibility object.

Hi heckj,

The accessibilityChildren API reference introduced this year has an example that uses Canvas; this modifier allows you to provide accessibility child elements for any view, including Canvas.

Let me know if you have additional questions on this!