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

Possible Strategy to use SwiftUI snapshots on a mac with ImageRenderer #888

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

doozMen
Copy link
Contributor

@doozMen doozMen commented Aug 8, 2024

assertSnapshot(of: Text("Hello"), as: .image) will not compile or give runtime crash due to missing frame

  • there is an ambiguity related to the extension in SnapShotting. There the .image for a SwiftUI view only exists if the format is a UIImage, but on macOS that does not exist
  • when running the current implementation requires a frame to be set on the SwiftUI view.

I added a test that runs on macOS and IOS and produces a snapshot. It uses ImageRenderer which is only available as of iOS 16 and also on macOS it requires at least 13. So using it is not a general solution. It however solves/bypasses the issues I had with making a simple snaphot of a swiftUI view.

I'm not sure this is a good solution or more of a workaround? But I think it might document a problem and could be a strategy for some?

Might relate to issue #428, #533

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

Successfully merging this pull request may close these issues.

1 participant