Skip to content

Commit

Permalink
Make SwiftUI Logic Also use RenderingError enum (#210)
Browse files Browse the repository at this point in the history
* try this out

* just use .zero in SwiftUIRenderingStrategy
  • Loading branch information
NicoHinderling authored Nov 21, 2024
1 parent d0e1457 commit cdbf9cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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(.zero)), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
}
}
}
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)
}

#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

0 comments on commit cdbf9cc

Please sign in to comment.