cashapp / AccessibilitySnapshot

Easy regression testing for iOS accessibility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support SwiftUI previews

ZevEisenberg opened this issue · comments

I have no idea how feasible it would be to build this, given the requirement for hosted tests, but I'd love if I could wrap my SwiftUI previews in some utility from this library that would let me see my accessibility labels alongside my view while developing, instead of after the fact when snapshot testing.

My understanding is previews are rendered in a host app, so I don't think that would be a problem. One other requirement is the container needs to be added to a window so it can convert to the screen coordinate space. I'm guessing previews would need to use a window. The setup code would look something like this:

#Preview {
    let container = AccessibilitySnapshotView(
        containedView: theViewYouWantToSnapshot,
        viewRenderingMode: .drawHierarchyInRect,
        activationPointDisplayMode: .whenOverridden
    )

    // This part should run once the container is added to a window:
    try container.parseAccessibility(useMonochromeSnapshot: true)
    container.sizeToFit()

    return container
}

Maybe we could wrap the AccessibilitySnapshotView inside another container that calls the parse method when it's added to a window? I'm not really sure what the life cycle for a preview is.

I worked on a sketch of what this could look like: #213