Skip to content

Commit d6673e1

Browse files
authored
Rendering error (#90)
1 parent 0a6c708 commit d6673e1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Sources/SnapshotPreviewsCore/View+Snapshot.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import Foundation
1010
import SwiftUI
1111
import UIKit
1212

13-
enum RenderingError: Error {
14-
case failedRendering
13+
public enum RenderingError: Error {
14+
case failedRendering(CGSize)
1515
}
1616

1717
extension View {
1818
public func snapshot(
1919
layout: PreviewLayout,
2020
window: UIWindow,
2121
async: Bool,
22-
completion: @escaping (Result<UIImage, Error>, Float?) -> Void)
22+
completion: @escaping (Result<UIImage, RenderingError>, Float?) -> Void)
2323
{
2424
UIView.setAnimationsEnabled(false)
2525
let animationDisabledView = self.transaction { transaction in
@@ -82,7 +82,7 @@ extension View {
8282
layout: PreviewLayout,
8383
renderingMode: EmergeRenderingMode?,
8484
rootVC: UIViewController,
85-
controller: UIViewController) -> Result<UIImage, Error>
85+
controller: UIViewController) -> Result<UIImage, RenderingError>
8686
{
8787
let view = controller.view!
8888
let drawCode: (CGContext) -> Void
@@ -117,7 +117,7 @@ extension View {
117117
drawCode(context.cgContext)
118118
}
119119
if !success {
120-
return .failure(RenderingError.failedRendering)
120+
return .failure(RenderingError.failedRendering(targetSize))
121121
}
122122
return .success(image)
123123
}

Sources/SnapshottingSwift/Snapshots.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ class Snapshots {
102102
try await server.start()
103103
}
104104

105-
@MainActor func display(typeName: String, id: String) async -> (Result<UIImage, Error>, SnapshotPreviewsCore.Preview) {
105+
@MainActor func display(typeName: String, id: String) async -> (Result<UIImage, RenderingError>, SnapshotPreviewsCore.Preview) {
106106
await withCheckedContinuation { continuation in
107107
display(typeName: typeName, id: id) { result, preview in
108108
continuation.resume(returning: (result, preview))
109109
}
110110
}
111111
}
112112

113-
@MainActor func display(typeName: String, id: String, completion: @escaping (Result<UIImage, Error>, SnapshotPreviewsCore.Preview) -> Void) {
113+
@MainActor func display(typeName: String, id: String, completion: @escaping (Result<UIImage, RenderingError>, SnapshotPreviewsCore.Preview) -> Void) {
114114
let previewTypes = findPreviews { name in
115115
return name == typeName
116116
}
@@ -122,7 +122,7 @@ class Snapshots {
122122
}
123123
}
124124

125-
@MainActor func display(preview: SnapshotPreviewsCore.Preview, completion: @escaping (Result<UIImage, Error>, Float?) -> Void) throws {
125+
@MainActor func display(preview: SnapshotPreviewsCore.Preview, completion: @escaping (Result<UIImage, RenderingError>, Float?) -> Void) throws {
126126
var view = preview.view()
127127
view = AnyView(PreferredColorSchemeWrapper { view })
128128
view.snapshot(

0 commit comments

Comments
 (0)