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

FBSnapshotVerifyView doesn't seem to work well with SwiftUI #97

Closed
Czajnikowski opened this issue Jul 2, 2019 · 6 comments
Closed

FBSnapshotVerifyView doesn't seem to work well with SwiftUI #97

Czajnikowski opened this issue Jul 2, 2019 · 6 comments

Comments

@Czajnikowski
Copy link

Czajnikowski commented Jul 2, 2019

The issue happens in Xcode 11 beta 2 (11M337n) and beta 3 (11M362v). I know it's an early moment and maybe it's a bug in the SDK, but currently when I invoke this with recordMode = true I get a blank snapshot:

let viewController = UIHostingController(
    rootView: Text("yo")
)
viewController.view?.frame = CGRect(
    origin: CGPoint.zero,
    size: CGSize(width: 300, height: 500)
)
        
FBSnapshotVerifyView(viewController.view!)
@leohidalgo
Copy link

This has nothing to do with the library, if you check viewController.view this is empty (white), that happens to me too

@leohidalgo
Copy link

leohidalgo commented Jul 11, 2019

In this way, the image is well generated.

Option 1

    let vc = UIHostingController(rootView: ContentView())

    let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    window.rootViewController = vc
    window.makeKeyAndVisible()

    sut = vc.view

    FBSnapshotVerifyView(sut)

Option 2

    let vc = UIHostingController(rootView: ContentView())
    vc.view.frame = CGRect(x: 0, y: -1, width: 100, height: 100)
    vc.view.drawHierarchy(in: vc.view.bounds, afterScreenUpdates: true)
    sut = vc.view

@Czajnikowski
Copy link
Author

Yes, works well! Thanks for your help @leohidalgo 🍻😊

@leohidalgo
Copy link

I would like to discuss why this should be done now and not before. The both option run, why?, I don't know 😬

@Czajnikowski
Copy link
Author

I checked briefly transcriptions from WWDC vids (searching for „window”), but didn’t find any clue 🤷🏼‍♂️

@leohidalgo
Copy link

I think I have the answer,

https://developer.apple.com/documentation/swiftui/color
image

The view is only resolved to concrete when it is displayed, In our case in a UIWindow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants