add visionos support

This commit is contained in:
infinitepower18 2024-03-19 01:04:12 +00:00 committed by Shibo Lyu
parent c296f3e6e5
commit 1d66f10bff
4 changed files with 10 additions and 9 deletions

View file

@ -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.

View file

@ -6,7 +6,7 @@
//
import SwiftUI
#if os(iOS)
#if !os(macOS)
import UIKit
#endif
@ -144,13 +144,13 @@ public struct CropImageView<Controls: View, CutHole: View>: 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<Controls: View, CutHole: View>: 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):

View file

@ -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.
///

View file

@ -84,7 +84,7 @@ struct UnderlyingImageView: View {
var imageView: Image {
#if os(macOS)
Image(nsImage: image)
#elseif os(iOS)
#else
Image(uiImage: image)
#endif
}