-
Notifications
You must be signed in to change notification settings - Fork 9
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
Make SwiftUI Logic Also use RenderingError enum #210
Conversation
import UIKit | ||
import AccessibilitySnapshotCore | ||
import SnapshotSharedModels | ||
import CoreFoundation | ||
|
||
public enum RenderingError: Error { | ||
case failedRendering(CGSize) | ||
case maxSize(CGSize) | ||
case expandingViewTimeout(CGSize) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this outside of the #if canImport(UIKit) && !os(visionOS) && !os(watchOS) && !os(tvOS)
block. I had to import CoreFoundation to get CGSize, but I think that's fine for both UIKit / AppKit purposes
lmk otherwise
f5e4501
to
b0ddd87
Compare
@@ -41,7 +37,7 @@ public class SwiftUIRenderingStrategy: RenderingStrategy { | |||
if let image { | |||
completion(SnapshotResult(image: .success(image), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot)) | |||
} else { | |||
completion(SnapshotResult(image: .failure(SwiftUIRenderingError.renderingError), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot)) | |||
completion(SnapshotResult(image: .failure(RenderingError.failedRendering(image?.size ?? .zero)), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
image
is always null here because this is in the else block of the if let
so we can just use .zero
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫡
We had an issue where some mac previews were failing to render, and it was unclear why. We should have had the "zero width" situation handled, but it was only configured for UIKit rendering, not AppKit rendering.
I went ahead and made the AppKit/SwiftUI rendering use the same error enum type. Our backend/web should then parse this correctly