From f11704f4ebc9b03adce35f6b3240adf502bef612 Mon Sep 17 00:00:00 2001 From: ktiays Date: Wed, 4 Oct 2023 22:45:32 +0900 Subject: [PATCH] Add supports for tvOS targets --- Package.swift | 2 +- Sources/CyanExtensions/PlatformFont+Extension.swift | 2 +- Sources/CyanSwiftUI/AnimatedClickable.swift | 4 +++- Sources/CyanSwiftUI/Extensions/Color.swift | 10 +++++----- Sources/CyanUI/Banner/BannerManager.swift | 2 +- Sources/CyanUI/Banner/PillContainerView.swift | 2 +- .../CyanUI/Banner/PillContainerViewController.swift | 2 +- Sources/CyanUI/Duotone.swift | 12 ++++++------ Sources/CyanUI/SegmentedControl.swift | 4 ++++ Tests/CyanConcurrencyTests/ExtensionsTests.swift | 6 +++--- 10 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Package.swift b/Package.swift index 08468ff..136289f 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "CyanKit", - platforms: [.iOS(.v14), .macOS(.v11)], + platforms: [.iOS(.v14), .macOS(.v11), .tvOS(.v14)], products: [ .library( name: "CyanKit", diff --git a/Sources/CyanExtensions/PlatformFont+Extension.swift b/Sources/CyanExtensions/PlatformFont+Extension.swift index a4b59cf..f4551d8 100644 --- a/Sources/CyanExtensions/PlatformFont+Extension.swift +++ b/Sources/CyanExtensions/PlatformFont+Extension.swift @@ -3,7 +3,7 @@ // Copyright (c) 2022 ktiays. All rights reserved. // -#if os(iOS) +#if canImport(UIKit) import UIKit public typealias PlatformFont = UIFont #else diff --git a/Sources/CyanSwiftUI/AnimatedClickable.swift b/Sources/CyanSwiftUI/AnimatedClickable.swift index 75c026b..e3348ce 100644 --- a/Sources/CyanSwiftUI/AnimatedClickable.swift +++ b/Sources/CyanSwiftUI/AnimatedClickable.swift @@ -167,7 +167,7 @@ private struct _AnimatedClickableView: View where V: View { : configuration.identityModifier) #if os(iOS) .overlay(gestureView()) - #else + #elseif os(macOS) .highPriorityGesture(dragGesture()) #endif } @@ -200,6 +200,7 @@ private struct _AnimatedClickableView: View where V: View { } #endif + #if os(macOS) private func dragGesture() -> some Gesture { DragGesture(minimumDistance: 0) .onChanged { value in @@ -222,6 +223,7 @@ private struct _AnimatedClickableView: View where V: View { } } } + #endif private func sizeReader() -> some View { GeometryReader { proxy in diff --git a/Sources/CyanSwiftUI/Extensions/Color.swift b/Sources/CyanSwiftUI/Extensions/Color.swift index dedfd1c..da9fd4d 100644 --- a/Sources/CyanSwiftUI/Extensions/Color.swift +++ b/Sources/CyanSwiftUI/Extensions/Color.swift @@ -9,8 +9,8 @@ import CyanExtensions public extension Color { init(platformColor: PlatformColor) { - #if os(iOS) - if #available(iOS 15.0, *) { + #if canImport(UIKit) + if #available(iOS 15.0, tvOS 15.0, *) { self.init(uiColor: platformColor) } else { self.init(platformColor) @@ -63,11 +63,11 @@ public extension Color { static let systemTeal: Color = .init(platformColor: .systemTeal) /// A context-dependent cyan color that automatically adapts to the current trait environment. - @available(iOS 15.0, macOS 12.0, *) + @available(iOS 15.0, macOS 12.0, tvOS 15.0, *) static let systemCyan: Color = .init(platformColor: .systemCyan) /// A context-dependent mint color that automatically adapts to the current trait environment. - @available(iOS 15.0, macOS 12.0, *) + @available(iOS 15.0, macOS 12.0, tvOS 15.0, *) static let systemMint: Color = .init(platformColor: .systemMint) @@ -76,7 +76,7 @@ public extension Color { /// A context-dependent gray color that automatically adapts to the current trait environment. static let systemGray: Color = .init(platformColor: .systemGray) - #if canImport(UIKit) + #if canImport(UIKit) && !os(tvOS) /// A second-level shade of gray that adapts to the environment. /// diff --git a/Sources/CyanUI/Banner/BannerManager.swift b/Sources/CyanUI/Banner/BannerManager.swift index 0afd105..6a5c507 100644 --- a/Sources/CyanUI/Banner/BannerManager.swift +++ b/Sources/CyanUI/Banner/BannerManager.swift @@ -3,7 +3,7 @@ // Copyright (c) 2022 ktiays. All rights reserved. // -#if canImport(UIKit) +#if os(iOS) || targetEnvironment(macCatalyst) import SwiftUI import UIKit diff --git a/Sources/CyanUI/Banner/PillContainerView.swift b/Sources/CyanUI/Banner/PillContainerView.swift index 5946a25..a1e5c08 100644 --- a/Sources/CyanUI/Banner/PillContainerView.swift +++ b/Sources/CyanUI/Banner/PillContainerView.swift @@ -3,7 +3,7 @@ // Copyright (c) 2022 ktiays. All rights reserved. // -#if canImport(UIKit) +#if os(iOS) || targetEnvironment(macCatalyst) import UIKit import SwiftUI diff --git a/Sources/CyanUI/Banner/PillContainerViewController.swift b/Sources/CyanUI/Banner/PillContainerViewController.swift index 43cfd4c..218ce22 100644 --- a/Sources/CyanUI/Banner/PillContainerViewController.swift +++ b/Sources/CyanUI/Banner/PillContainerViewController.swift @@ -3,7 +3,7 @@ // Copyright (c) 2022 ktiays. All rights reserved. // -#if canImport(UIKit) +#if os(iOS) || targetEnvironment(macCatalyst) import UIKit import SwiftUI diff --git a/Sources/CyanUI/Duotone.swift b/Sources/CyanUI/Duotone.swift index 07b1298..8849b61 100644 --- a/Sources/CyanUI/Duotone.swift +++ b/Sources/CyanUI/Duotone.swift @@ -6,7 +6,7 @@ import SwiftUI import CyanExtensions -@available(iOS 15.0, macOS 12.0, *) +@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) public protocol DuotoneIconStyle { typealias Configuration = DuotoneIconConfiguration @@ -17,14 +17,14 @@ public protocol DuotoneIconStyle { } -@available(iOS 15.0, macOS 12.0, *) +@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) public struct DuotoneIconConfiguration { public let context: GraphicsContext public let bounds: CGRect public let isHighlighted: Bool } -@available(iOS 15.0, macOS 12.0, *) +@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) public struct IconColorConfiguration { public let primaryColor: Color public let highlightPrimaryColor: Color @@ -46,7 +46,7 @@ public struct IconColorConfiguration { } } -@available(iOS 15.0, macOS 12.0, *) +@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) public struct IconColorConfigurationKey: EnvironmentKey { public static var defaultValue: IconColorConfiguration? { let primaryColor: Color = .init(lightColor: .label, darkColor: .white) @@ -56,7 +56,7 @@ public struct IconColorConfigurationKey: EnvironmentKey { } } -@available(iOS 15.0, macOS 12.0, *) +@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) public extension EnvironmentValues { var iconColorConfiguration: IconColorConfiguration? { get { self[IconColorConfigurationKey.self] } @@ -64,7 +64,7 @@ public extension EnvironmentValues { } } -@available(iOS 15.0, macOS 12.0, *) +@available(iOS 15.0, macOS 12.0, tvOS 15.0, *) public struct DuotoneIcon: View where S: DuotoneIconStyle { @Environment(\.iconColorConfiguration) var iconColorConfiguration diff --git a/Sources/CyanUI/SegmentedControl.swift b/Sources/CyanUI/SegmentedControl.swift index bd8a6e4..ecb39ff 100644 --- a/Sources/CyanUI/SegmentedControl.swift +++ b/Sources/CyanUI/SegmentedControl.swift @@ -3,6 +3,8 @@ // Copyright (c) 2021 ktiays. All rights reserved. // +#if os(iOS) || targetEnvironment(macCatalyst) + import SwiftUI import CyanExtensions @@ -179,3 +181,5 @@ struct SegmentedControl_Previews: PreviewProvider { PreviewView() } } + +#endif diff --git a/Tests/CyanConcurrencyTests/ExtensionsTests.swift b/Tests/CyanConcurrencyTests/ExtensionsTests.swift index 4ccb091..667cd4f 100644 --- a/Tests/CyanConcurrencyTests/ExtensionsTests.swift +++ b/Tests/CyanConcurrencyTests/ExtensionsTests.swift @@ -6,13 +6,13 @@ import XCTest @testable import CyanConcurrency -@available(macOS 13.0, iOS 16.0, *) +@available(macOS 13.0, iOS 16.0, tvOS 16.0, *) fileprivate func fakeAsyncTransformer(_ input: Int) async -> String { try? await Task.sleep(for: .milliseconds(10)) return "\(input)" } -@available(macOS 13.0, iOS 16.0, *) +@available(macOS 13.0, iOS 16.0, tvOS 16.0, *) fileprivate func fakeAsyncTransformerThrows(_ input: Int) async throws -> String { if input % 2 == 0 { struct _DummyError: Error { } @@ -21,7 +21,7 @@ fileprivate func fakeAsyncTransformerThrows(_ input: Int) async throws -> String return await fakeAsyncTransformer(input) } -@available(macOS 13.0, iOS 16.0, *) +@available(macOS 13.0, iOS 16.0, tvOS 16.0, *) final class ConcurrencyAlgorithmsTests: XCTestCase { func testArrayMap() async {