BarredEwe / Prefire

🔥 A library based on SwiftUI Preview, for easy generation: Playbook view, Snapshot and Accessibility tests
Apache License 2.0
251 stars 16 forks source link

Device/Height independent Tests #26

Closed Velin92 closed 7 months ago

Velin92 commented 9 months ago

Would be nice to have the preview of the tests be device or height independent in some way. What I mean is that it seems that there is no way to generate the previews so that they match exactly their fitting size. This would be very useful to render scroll views for example, or very huge vertical stack layouts that do not fit a single iPhone screen. Maybe the test code could only pick the device width (and not be completely device independent), and then have the height get rendered based on a size that fits it. Or maybe in the configuration you could specify a specific device width (either from a device family like iPhone X or giving the px/pts value directly).

I am actually playing around myself with the .stencil code to see if I can achieve something like that but so far I did not find a solution that works generally.

BarredEwe commented 9 months ago

Hi!

The dynamic height can be set using the standard function in preview:

.previewLayout(.sizeThatFits)

Here is an example:

struct TestView_Preview: PreviewProvider, PrefireProvider {
    static var previews: some View {
        VStack {
            ForEach(0..<60) { _ in
                Text("Test")
            }
        }
        .previewLayout(.sizeThatFits)
    }
}
And here is the result: