Skip to content

Commit

Permalink
Merge pull request #10 from bullinnyc/add-support-tvOS-watchOS-visionOS
Browse files Browse the repository at this point in the history
Add support tvOS, watchOS, visionOS.
  • Loading branch information
bullinnyc authored Feb 11, 2024
2 parents 43f008c + c8a115e commit 6babc1e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
macos: ['macos-13']
scheme: ['CachedAsyncImage']
command: ['test']
platform: ['macOS', 'iOS']
platform: ['iOS', 'macOS', 'tvOS', 'watchOS']
steps:
- name: Switch xcode to ${{ matrix.xcode }}
uses: maxim-lobanov/setup-xcode@v1.6.0
Expand Down
6 changes: 3 additions & 3 deletions Examples/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import SwiftUI
import CachedAsyncImage

@available(iOS 15.0, macOS 12.0, *)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
struct ContentView: View {
// MARK: - Private Properties

Expand Down Expand Up @@ -97,7 +97,7 @@ struct ContentView: View {

// MARK: - Ext. Configure views

@available(iOS 15.0, macOS 12.0, *)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
extension ContentView {
func placeholder(_ progress: String) -> some View {
ZStack {
Expand Down Expand Up @@ -149,7 +149,7 @@ extension ContentView {

// MARK: - Preview Provider

@available(iOS 15.0, macOS 12.0, *)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -8,7 +8,10 @@ let package = Package(
platforms: [
// Add support for all platforms starting from a specific version.
.iOS(.v14),
.macOS(.v11)
.macOS(.v11),
.tvOS(.v14),
.watchOS(.v7),
.visionOS(.v1)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ struct MyView: View {
```

## Requirements
- iOS 14.0 +
- macOS 11.0 +
- iOS 14.0 + / macOS 11.0 + / tvOS 14.0 + / watchOS 7.0 + / visionOS 1.0 +
- [SwiftUI](https://developer.apple.com/xcode/swiftui/)

## License
Expand Down
24 changes: 19 additions & 5 deletions Sources/CachedAsyncImage/Resources/ResourcesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#if canImport(UIKit)
import UIKit

#if os(watchOS)
import SwiftUI
#endif

/// Resources manager typealias.
public typealias RM = ResourcesManager

Expand All @@ -17,11 +21,7 @@ public final class ResourcesManager {
// MARK: - Public Properties

/// An object that stores color data.
public static let snow = UIColor(
named: "snow",
in: Bundle.module,
compatibleWith: nil
) ?? UIColor()
public static let snow = getColor(with: "snow")

// MARK: - Public Methods

Expand All @@ -33,6 +33,20 @@ public final class ResourcesManager {
public static func image(_ name: String) -> UIImage? {
UIImage(named: name, in: Bundle.module, with: nil)
}

// MARK: - Private Methods

private static func getColor(with name: String) -> UIColor {
#if os(watchOS)
UIColor(Color(name, bundle: Bundle.module))
#elseif os(iOS) || os(tvOS) || os(visionOS)
UIColor(
named: name,
in: Bundle.module,
compatibleWith: nil
) ?? UIColor()
#endif
}
}
#elseif canImport(AppKit)
import AppKit
Expand Down
2 changes: 1 addition & 1 deletion Sources/CachedAsyncImage/Services/CrossPlatformImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2023 Dmitry Kononchuk. All rights reserved.
//

#if os(iOS)
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
import UIKit
import SwiftUI

Expand Down
18 changes: 16 additions & 2 deletions Sources/CachedAsyncImage/Views/CachedAsyncImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ struct CachedAsyncImage_Previews: PreviewProvider {
.font(.footnote)
.multilineTextAlignment(.center)
.conditional { view in
if #available(iOS 15.0, macOS 12.0, *) {
if #available(
iOS 15.0,
macOS 12.0,
tvOS 15.0,
watchOS 8.0,
visionOS 1.0,
*
) {
view
.foregroundStyle(.red)
} else {
Expand All @@ -146,7 +153,14 @@ struct CachedAsyncImage_Previews: PreviewProvider {
label: {
Text("Retry")
.conditional { view in
if #available(iOS 15.0, macOS 12.0, *) {
if #available(
iOS 15.0,
macOS 12.0,
tvOS 15.0,
watchOS 8.0,
visionOS 1.0,
*
) {
view
.foregroundStyle(.black)
} else {
Expand Down

0 comments on commit 6babc1e

Please sign in to comment.