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

Make SwiftUI Logic Also use RenderingError enum #210

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SnapshotPreviewsCore/AppKitRenderingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class AppKitRenderingStrategy: RenderingStrategy {
let image = vc?.view.snapshot()
completion(
SnapshotResult(
image: image != nil ? .success(image!) : .failure(SwiftUIRenderingError.renderingError),
image: image != nil ? .success(image!) : .failure(RenderingError.failedRendering(vc?.view.bounds.size ?? .zero)),
precision: precision,
accessibilityEnabled: accessibilityEnabled,
accessibilityMarkers: nil,
Expand Down
6 changes: 1 addition & 5 deletions Sources/SnapshotPreviewsCore/SwiftUIRenderingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
import Foundation
import SwiftUI

enum SwiftUIRenderingError: Error {
case renderingError
}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, visionOS 1.0, *)
public class SwiftUIRenderingStrategy: RenderingStrategy {

Expand Down Expand Up @@ -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))
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

}
}
}
14 changes: 8 additions & 6 deletions Sources/SnapshotPreviewsCore/View+Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
// Created by Noah Martin on 12/22/22.
//

#if canImport(UIKit) && !os(visionOS) && !os(watchOS) && !os(tvOS)
import Foundation
import SwiftUI
import UIKit
import AccessibilitySnapshotCore
import SnapshotSharedModels
import CoreFoundation

public enum RenderingError: Error {
case failedRendering(CGSize)
case maxSize(CGSize)
case expandingViewTimeout(CGSize)
}
Copy link
Collaborator Author

@NicoHinderling NicoHinderling Nov 21, 2024

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


#if canImport(UIKit) && !os(visionOS) && !os(watchOS) && !os(tvOS)
import Foundation
import SwiftUI
import UIKit
import AccessibilitySnapshotCore
import SnapshotSharedModels

extension AccessibilityMarker: AccessibilityMark {
public var accessibilityShape: MarkerShape {
switch shape {
Expand Down
Loading