Skip to content

Commit

Permalink
Fix VisionOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
alfianlosari committed Jul 6, 2024
1 parent 7a2ecaa commit 8e2fe1a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
21 changes: 8 additions & 13 deletions Sources/AIReceiptScanner/Image+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@ extension UIImage {
}
return scaledImage
}

func scaledPNGData() -> Data {
let targetSize = CGSize(
width: size.width / UIScreen.main.scale,
height: size.height / UIScreen.main.scale)

let renderer = UIGraphicsImageRenderer(size: targetSize)
let resized = renderer.image { _ in
self.draw(in: .init(origin: .zero, size: targetSize))
}
return resized.pngData()!
}


func scaledJPGData(compressionQuality: CGFloat = 0.5) -> Data {
#if os(visionOS)
let targetSize = CGSize(
width: size.width / UITraitCollection.current.displayScale,
height: size.height / UITraitCollection.current.displayScale)
#else
let targetSize = CGSize(
width: size.width / UIScreen.main.scale,
height: size.height / UIScreen.main.scale)
#endif


let renderer = UIGraphicsImageRenderer(size: targetSize)
let resized = renderer.image { _ in
Expand Down
2 changes: 1 addition & 1 deletion Sources/AIReceiptScanner/UI/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import SwiftUI

#if !os(macOS)
#if os(iOS)
struct CameraView: UIViewControllerRepresentable {
@Binding var isPresented: Bool
@Binding var image: ReceiptImage?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ public struct ReceiptPickerScannerDefaultMenuView: View {
}

public var body: some View {
#if os(macOS)
#if os(macOS) || os(visionOS)
VStack {
if let image = scanStatus.receiptImage {
image
.resizable()
.scaledToFit()
.clipped()
#if os(macOS)
.frame(maxWidth: .infinity, maxHeight: .infinity)
#endif
}

ReceiptPickerScannerMenuView(apiKey: apiKey, scanStatus: $scanStatus) {
Expand Down

0 comments on commit 8e2fe1a

Please sign in to comment.