From e11a3cc7cf0d60106b76c5a091711e16c337fb44 Mon Sep 17 00:00:00 2001 From: infinitepower18 <44692189+infinitepower18@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:04:12 +0000 Subject: [PATCH] add visionos support --- Package.swift | 5 +++-- Sources/CropImage/CropImageView.swift | 10 +++++----- Sources/CropImage/PlatformImage.swift | 2 +- Sources/CropImage/UnderlyingImageView.swift | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index 948f859..f88e851 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.8 +// swift-tools-version: 5.10 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -7,7 +7,8 @@ let package = Package( name: "CropImage", platforms: [ .iOS(.v14), - .macOS(.v13) + .macOS(.v13), + .visionOS(.v1) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. diff --git a/Sources/CropImage/CropImageView.swift b/Sources/CropImage/CropImageView.swift index adc0777..c58cdd8 100644 --- a/Sources/CropImage/CropImageView.swift +++ b/Sources/CropImage/CropImageView.swift @@ -6,7 +6,7 @@ // import SwiftUI -#if os(iOS) +#if !os(macOS) import UIKit #endif @@ -144,13 +144,13 @@ public struct CropImageView: View { if #available(iOS 16.0, macOS 13.0, *) { let renderer = ImageRenderer(content: snapshotView) renderer.scale = targetScale -#if os(iOS) +#if !os(macOS) if let image = renderer.uiImage { return image } else { throw CropError.imageRendererReturnedNil } -#elseif os(macOS) +#else if let image = renderer.nsImage { return image } else { @@ -160,7 +160,7 @@ public struct CropImageView: View { } else { #if os(macOS) fatalError("Cropping is not supported on macOS versions before Ventura 13.0.") -#elseif os(iOS) +#else let window = UIWindow(frame: CGRect(origin: .zero, size: targetSize)) let hosting = UIHostingController(rootView: snapshotView) hosting.view.frame = window.frame @@ -250,7 +250,7 @@ struct CropImageView_Previews: PreviewProvider { case let .success(croppedImage): #if os(macOS) Image(nsImage: croppedImage) -#elseif os(iOS) +#else Image(uiImage: croppedImage) #endif case let .failure(error): diff --git a/Sources/CropImage/PlatformImage.swift b/Sources/CropImage/PlatformImage.swift index 617ea5f..7f45b90 100644 --- a/Sources/CropImage/PlatformImage.swift +++ b/Sources/CropImage/PlatformImage.swift @@ -13,7 +13,7 @@ import AppKit /// /// On macOS, it's `NSImage` and on iOS it's `UIImage`. public typealias PlatformImage = NSImage -#elseif os(iOS) +#else import UIKit /// The image object type, aliased to each platform. /// diff --git a/Sources/CropImage/UnderlyingImageView.swift b/Sources/CropImage/UnderlyingImageView.swift index 7166bf4..e49de8a 100644 --- a/Sources/CropImage/UnderlyingImageView.swift +++ b/Sources/CropImage/UnderlyingImageView.swift @@ -84,7 +84,7 @@ struct UnderlyingImageView: View { var imageView: Image { #if os(macOS) Image(nsImage: image) -#elseif os(iOS) +#else Image(uiImage: image) #endif }