Fixes tvOS and watchOS

This commit is contained in:
Shaps Benkau 2023-02-01 09:06:15 +00:00
parent 2cf2c091c3
commit c4936d438e
17 changed files with 51 additions and 27 deletions

View File

@ -11,21 +11,21 @@ internal typealias PlatformViewController = UIViewController
extension UIScreen { extension UIScreen {
@nonobjc @nonobjc
public static var mainScreen: UIScreen { public static var mainScreen: UIScreen { .main }
return .main
}
} }
extension UIImage { extension UIImage {
public var png: Data? { public var png: Data? { pngData() }
return self.pngData() public func jpg(quality: CGFloat) -> Data? { jpegData(compressionQuality: quality) }
} }
public func jpg(quality: CGFloat) -> Data? { extension CGContext {
return self.jpegData(compressionQuality: quality) internal static var current: CGContext? {
UIGraphicsGetCurrentContext()
} }
} }
#elseif os(macOS) #elseif os(macOS)
import AppKit import AppKit
@ -38,13 +38,8 @@ internal typealias PlatformScrollView = NSScrollView
internal typealias PlatformViewController = NSViewController internal typealias PlatformViewController = NSViewController
extension NSScreen { extension NSScreen {
public static var mainScreen: NSScreen { public static var mainScreen: NSScreen { NSScreen.main! }
return NSScreen.main! public var scale: CGFloat { backingScaleFactor }
}
public var scale: CGFloat {
return backingScaleFactor
}
} }
extension NSImage { extension NSImage {
@ -57,16 +52,9 @@ extension NSImage {
} }
} }
#endif
extension CGContext { extension CGContext {
internal static var current: CGContext? { internal static var current: CGContext? {
#if os(OSX) NSGraphicsContext.current?.cgContext
return NSGraphicsContext.current?.cgContext
#else
return UIGraphicsGetCurrentContext()
#endif
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
public extension Backport<Any> { public extension Backport<Any> {
@ -76,3 +77,4 @@ private extension NSView {
} }
} }
#endif #endif
#endif

View File

@ -1,4 +1,5 @@
import Photos #if os(iOS)
import PhotosUI
/// Represents a `PHFetchResult` that can be used as a `RandomAccessCollection` in a SwiftUI view such as `List`, `ForEach`, etc... /// Represents a `PHFetchResult` that can be used as a `RandomAccessCollection` in a SwiftUI view such as `List`, `ForEach`, etc...
internal struct MediaResults<Result>: RandomAccessCollection where Result: PHObject { internal struct MediaResults<Result>: RandomAccessCollection where Result: PHObject {
@ -38,3 +39,4 @@ internal final class ResultsObserver<Result>: NSObject, ObservableObject, PHPhot
} }
} }
#endif

View File

@ -1,5 +1,6 @@
#if os(iOS)
import Foundation import Foundation
import Photos import PhotosUI
internal extension PHFetchOptions { internal extension PHFetchOptions {
@ -61,3 +62,4 @@ internal extension PHFetchOptions {
} }
} }
#endif

View File

@ -1,6 +1,8 @@
#if os(iOS)
import SwiftUI import SwiftUI
import Photos import PhotosUI
extension PHObject: Identifiable { extension PHObject: Identifiable {
public var id: String { localIdentifier } public var id: String { localIdentifier }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(iOS)
import Photos import Photos
import SwiftUI import SwiftUI
@ -58,3 +59,4 @@ internal final class AssetObserver: NSObject, ObservableObject, PHPhotoLibraryCh
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(iOS)
import Photos import Photos
import SwiftUI import SwiftUI
@ -93,3 +94,4 @@ internal extension FetchAssetCollection {
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(iOS)
import Photos import Photos
import SwiftUI import SwiftUI
@ -114,3 +115,4 @@ internal extension FetchAssetList {
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(iOS)
import Photos import Photos
import SwiftUI import SwiftUI
@ -103,3 +104,4 @@ internal extension FetchCollectionList {
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(iOS)
import SwiftUI import SwiftUI
/* /*
@ -15,3 +16,4 @@ private extension Backport where Wrapped: View {
} }
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
@available(iOS, deprecated: 16) @available(iOS, deprecated: 16)
@ -59,3 +60,4 @@ public extension Backport.ShareLink where Wrapped == Any {
self.preview = { .init($0.absoluteString) } self.preview = { .init($0.absoluteString) }
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
@available(iOS, deprecated: 16) @available(iOS, deprecated: 16)
@ -41,3 +42,4 @@ public extension Backport.ShareLink where Wrapped == Any {
self.preview = { .init($0.absoluteString) } self.preview = { .init($0.absoluteString) }
} }
} }
#endif

View File

@ -1,5 +1,8 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
#if canImport(LinkPresentation)
import LinkPresentation import LinkPresentation
#endif
@available(iOS, deprecated: 16) @available(iOS, deprecated: 16)
@available(macOS, deprecated: 13) @available(macOS, deprecated: 13)
@ -65,3 +68,4 @@ public extension Backport where Wrapped == Any {
// override func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { subject ?? "" } // override func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { subject ?? "" }
// //
//} //}
#endif

View File

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
#if os(macOS) || os(iOS)
extension View { extension View {
@ViewBuilder @ViewBuilder
func shareSheet<Data>(item activityItems: Binding<ActivityItem<Data>?>) -> some View where Data: RandomAccessCollection, Data.Element: Shareable { func shareSheet<Data>(item activityItems: Binding<ActivityItem<Data>?>) -> some View where Data: RandomAccessCollection, Data.Element: Shareable {
@ -10,6 +11,7 @@ extension View {
#endif #endif
} }
} }
#endif
#if os(macOS) #if os(macOS)

View File

@ -1,3 +1,4 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
@available(iOS, deprecated: 16) @available(iOS, deprecated: 16)
@ -59,3 +60,4 @@ public extension Backport.ShareLink where Wrapped == Any {
self.preview = { .init($0.absoluteString) } self.preview = { .init($0.absoluteString) }
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
@available(iOS, deprecated: 16) @available(iOS, deprecated: 16)
@ -41,3 +42,4 @@ public extension Backport.ShareLink where Wrapped == Any {
self.preview = { .init($0.absoluteString) } self.preview = { .init($0.absoluteString) }
} }
} }
#endif

View File

@ -1,3 +1,4 @@
#if os(macOS) || os(iOS)
import SwiftUI import SwiftUI
@available(iOS, deprecated: 16.0) @available(iOS, deprecated: 16.0)
@ -7,6 +8,8 @@ import SwiftUI
/// TEMPORARY, DO NOT RELY ON THIS! /// TEMPORARY, DO NOT RELY ON THIS!
/// ///
/// - Note: This **will be removed** in an upcoming release, regardless of semantic versioning /// - Note: This **will be removed** in an upcoming release, regardless of semantic versioning
@available(iOS, message: "This **will be removed** in an upcoming release, regardless of semantic versioning")
@available(macOS, message: "This **will be removed** in an upcoming release, regardless of semantic versioning")
public protocol Shareable { public protocol Shareable {
var pathExtension: String { get } var pathExtension: String { get }
var itemProvider: NSItemProvider? { get } var itemProvider: NSItemProvider? { get }
@ -75,3 +78,4 @@ extension PlatformImage: Shareable {
} }
} }
} }
#endif