Skip to content

Catalyst compatibility #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions Sources/SwiftUIKit/Images/ImageRepresentable+Resized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@

import Foundation

#if canImport(AppKit)
#if canImport(UIKit)
import UIKit

public extension UIImage {

/// Create a resized copy of the image.
func resized(to size: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(in: CGRect(origin: CGPoint.zero, size: size))
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result
}
}
#elseif canImport(AppKit)
import AppKit

public extension NSImage {
Expand All @@ -26,23 +40,6 @@ public extension NSImage {
}
#endif


#if canImport(UIKit)
import UIKit

public extension UIImage {

/// Create a resized copy of the image.
func resized(to size: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(in: CGRect(origin: CGPoint.zero, size: size))
let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return result
}
}
#endif

public extension ImageRepresentable {

/// Create a resized copy of the image with a new height.
Expand Down
14 changes: 6 additions & 8 deletions Sources/SwiftUIKit/Images/ImageRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@

import SwiftUI

#if canImport(AppKit)
import class AppKit.NSImage
#if canImport(UIKit)
import class UIKit.UIImage

/**
This typealias helps bridging UIKit and AppKit when working
with images in a multi-platform context.
*/
public typealias ImageRepresentable = NSImage
#endif

#if canImport(UIKit)
import class UIKit.UIImage
public typealias ImageRepresentable = UIImage
#elseif canImport(AppKit)
import class AppKit.NSImage

/**
This typealias helps bridging UIKit and AppKit when working
with images in a multi-platform context.
*/
public typealias ImageRepresentable = UIImage
public typealias ImageRepresentable = NSImage
#endif

public extension Image {
Expand Down
Loading