Skip to content

Commit

Permalink
Rendering error (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Feb 2, 2024
1 parent 0a6c708 commit d6673e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Sources/SnapshotPreviewsCore/View+Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Foundation
import SwiftUI
import UIKit

enum RenderingError: Error {
case failedRendering
public enum RenderingError: Error {
case failedRendering(CGSize)
}

extension View {
public func snapshot(
layout: PreviewLayout,
window: UIWindow,
async: Bool,
completion: @escaping (Result<UIImage, Error>, Float?) -> Void)
completion: @escaping (Result<UIImage, RenderingError>, Float?) -> Void)
{
UIView.setAnimationsEnabled(false)
let animationDisabledView = self.transaction { transaction in
Expand Down Expand Up @@ -82,7 +82,7 @@ extension View {
layout: PreviewLayout,
renderingMode: EmergeRenderingMode?,
rootVC: UIViewController,
controller: UIViewController) -> Result<UIImage, Error>
controller: UIViewController) -> Result<UIImage, RenderingError>
{
let view = controller.view!
let drawCode: (CGContext) -> Void
Expand Down Expand Up @@ -117,7 +117,7 @@ extension View {
drawCode(context.cgContext)
}
if !success {
return .failure(RenderingError.failedRendering)
return .failure(RenderingError.failedRendering(targetSize))
}
return .success(image)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/SnapshottingSwift/Snapshots.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class Snapshots {
try await server.start()
}

@MainActor func display(typeName: String, id: String) async -> (Result<UIImage, Error>, SnapshotPreviewsCore.Preview) {
@MainActor func display(typeName: String, id: String) async -> (Result<UIImage, RenderingError>, SnapshotPreviewsCore.Preview) {
await withCheckedContinuation { continuation in
display(typeName: typeName, id: id) { result, preview in
continuation.resume(returning: (result, preview))
}
}
}

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

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

0 comments on commit d6673e1

Please sign in to comment.