Skip to content
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 SwiftUI previews #164

Open
ZevEisenberg opened this issue Oct 9, 2023 · 2 comments
Open

Support SwiftUI previews #164

ZevEisenberg opened this issue Oct 9, 2023 · 2 comments
Labels
enhancement Request for a new feature or improvement to an existing feature

Comments

@ZevEisenberg
Copy link
Contributor

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.

@NickEntin
Copy link
Collaborator

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.

@NickEntin NickEntin added the enhancement Request for a new feature or improvement to an existing feature label Oct 17, 2023
@DavidBrunow
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for a new feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants