mirror of
https://github.com/laosb/CropImage.git
synced 2025-04-30 15:41:08 +00:00
add visionos support
This commit is contained in:
parent
c296f3e6e5
commit
1d66f10bff
4 changed files with 10 additions and 9 deletions
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -84,7 +84,7 @@ struct UnderlyingImageView: View {
|
|||
var imageView: Image {
|
||||
#if os(macOS)
|
||||
Image(nsImage: image)
|
||||
#elseif os(iOS)
|
||||
#else
|
||||
Image(uiImage: image)
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue