Skip to content

Commit

Permalink
Max size (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Mar 26, 2024
1 parent af5c23f commit 8a82556
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/SnapshotPreviewsCore/View+Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AccessibilitySnapshotCore

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

public struct SnapshotResult {
Expand Down Expand Up @@ -117,7 +118,8 @@ extension View {
layout: PreviewLayout,
renderingMode: EmergeRenderingMode?,
rootVC: UIViewController,
targetView: UIView) -> Result<UIImage, RenderingError>
targetView: UIView,
maxSize: Double = 1_000_000) -> Result<UIImage, RenderingError>
{
let view = targetView
let drawCode: (CGContext) -> Void
Expand Down Expand Up @@ -147,6 +149,9 @@ extension View {
success = rootVC.view.render(size: targetSize, mode: renderingMode, context: ctx)
}
}
if targetSize.height > maxSize || targetSize.width > maxSize {
return .failure(RenderingError.maxSize(targetSize))
}
let renderer = UIGraphicsImageRenderer(size: targetSize)
let image = renderer.image { context in
drawCode(context.cgContext)
Expand Down

0 comments on commit 8a82556

Please sign in to comment.