Skip to content

Commit cdbf9cc

Browse files
Make SwiftUI Logic Also use RenderingError enum (#210)
* try this out * just use .zero in SwiftUIRenderingStrategy
1 parent d0e1457 commit cdbf9cc

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Sources/SnapshotPreviewsCore/AppKitRenderingStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class AppKitRenderingStrategy: RenderingStrategy {
5252
let image = vc?.view.snapshot()
5353
completion(
5454
SnapshotResult(
55-
image: image != nil ? .success(image!) : .failure(SwiftUIRenderingError.renderingError),
55+
image: image != nil ? .success(image!) : .failure(RenderingError.failedRendering(vc?.view.bounds.size ?? .zero)),
5656
precision: precision,
5757
accessibilityEnabled: accessibilityEnabled,
5858
accessibilityMarkers: nil,

Sources/SnapshotPreviewsCore/SwiftUIRenderingStrategy.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
import Foundation
99
import SwiftUI
1010

11-
enum SwiftUIRenderingError: Error {
12-
case renderingError
13-
}
14-
1511
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, visionOS 1.0, *)
1612
public class SwiftUIRenderingStrategy: RenderingStrategy {
1713

@@ -41,7 +37,7 @@ public class SwiftUIRenderingStrategy: RenderingStrategy {
4137
if let image {
4238
completion(SnapshotResult(image: .success(image), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
4339
} else {
44-
completion(SnapshotResult(image: .failure(SwiftUIRenderingError.renderingError), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
40+
completion(SnapshotResult(image: .failure(RenderingError.failedRendering(.zero)), precision: wrappedView.precision, accessibilityEnabled: wrappedView.accessibilityEnabled, accessibilityMarkers: [], colorScheme: colorScheme, appStoreSnapshot: wrappedView.appStoreSnapshot))
4541
}
4642
}
4743
}

Sources/SnapshotPreviewsCore/View+Snapshot.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
// Created by Noah Martin on 12/22/22.
66
//
77

8-
#if canImport(UIKit) && !os(visionOS) && !os(watchOS) && !os(tvOS)
9-
import Foundation
10-
import SwiftUI
11-
import UIKit
12-
import AccessibilitySnapshotCore
13-
import SnapshotSharedModels
8+
import CoreFoundation
149

1510
public enum RenderingError: Error {
1611
case failedRendering(CGSize)
1712
case maxSize(CGSize)
1813
case expandingViewTimeout(CGSize)
1914
}
2015

16+
#if canImport(UIKit) && !os(visionOS) && !os(watchOS) && !os(tvOS)
17+
import Foundation
18+
import SwiftUI
19+
import UIKit
20+
import AccessibilitySnapshotCore
21+
import SnapshotSharedModels
22+
2123
extension AccessibilityMarker: AccessibilityMark {
2224
public var accessibilityShape: MarkerShape {
2325
switch shape {

0 commit comments

Comments
 (0)