Prefire icon indicating copy to clipboard operation
Prefire copied to clipboard

Wait before capturing a snapshot

Open sparafinski opened this issue 2 years ago • 5 comments

Context 🕵️‍♀️

While attempting to capture a view that includes AsyncImage or revealing a component after a specified duration, it's been noticed that the resulting snapshot doesn't include images loaded via URL or views that appear with a slight delay. Even when using .snapshot(delay: 1.0), there's no noticeable improvement in this scenario.

What 🌱

To overcome this challenge, it would be helpful to incorporate an option to wait before taking the snapshot. This way, we can ensure that the snapshot accounts for the asynchronous loading of images and views that emerge after a delay.

Example of a view that isn't properly captured in the snapshot:

struct DummyView: View {
    @State var isButtonHidden = true
    var body: some View {
        VStack {
            Text("Some text")
            Text("Some text with delay")
                .opacity(isButtonHidden ? 0 : 1)

        }.onAppear {
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.isButtonHidden = false
            }
        }
    }
}

sparafinski avatar Nov 22 '23 17:11 sparafinski

It seems that this is a problem of the swift-snapshot-tests library. I found a PR in it that should fix this.

I'll try to think later about how to get around this inside the Prefire.

BarredEwe avatar Nov 23 '23 08:11 BarredEwe

Also, it seems that .preferredColorScheme(.dark) is not handled properly. I found a PR that states it should already work 🤔 using swift-snapshot-tests . Do you think it could be the same cause?

sparafinski avatar Nov 23 '23 16:11 sparafinski

It sounds like a bug in the Prefire. I set myself the task to fix it in the 2.0 release 😊

BarredEwe avatar Dec 04 '23 07:12 BarredEwe