We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
When taking an image snapshot of a SwiftUI View that uses a preference to affect it's size, the resulting image will:
This causes the view to either:
To Reproduce
Take a snapshot of this ExampleView as .image(layout: .sizeThatFits)
ExampleView
.image(layout: .sizeThatFits)
struct ExampleView: View { @State private var size: CGSize = .init(width: 20, height: 20) var body: some View { Color.red .preference(key: SizePreferenceKey.self, value: CGSize(width: 10, height: 10)) .frame(width: size.width, height: size.height) .onPreferenceChange(SizePreferenceKey.self) { newSize in size = newSize } .border(.black) } } struct SizePreferenceKey: PreferenceKey { typealias Value = CGSize static var defaultValue: Value = .init(width: 30, height: 30) static func reduce(value: inout Value, nextValue: () -> Value) { value } }
Expected behavior The image should be 10pt x 10pt matching the size of the red view with a black border.
Screenshots
The image is actually being created at 20pt x 20pt so there's extra space added around the view.
If the preference was set to a larger value (ie 50x50), the red view would be larger than the image causing the border to no longer be in the image.
Environment
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
When taking an image snapshot of a SwiftUI View that uses a preference to affect it's size, the resulting image will:
This causes the view to either:
To Reproduce
Take a snapshot of this
ExampleView
as.image(layout: .sizeThatFits)
Expected behavior
The image should be 10pt x 10pt matching the size of the red view with a black border.
Screenshots
The image is actually being created at 20pt x 20pt so there's extra space added around the view.
If the preference was set to a larger value (ie 50x50), the red view would be larger than the image causing the border to no longer be in the image.
Environment
The text was updated successfully, but these errors were encountered: