Skip to content

Commit

Permalink
Merge pull request #752 from zachwaugh/visionos-support
Browse files Browse the repository at this point in the history
Enable visionOS support for all APIs
  • Loading branch information
kean authored Feb 10, 2024
2 parents c42e725 + be94021 commit f73c59c
Show file tree
Hide file tree
Showing 33 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions Sources/Nuke/Caching/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit.UIApplication
#endif

Expand Down Expand Up @@ -55,7 +55,7 @@ final class Cache<Key: Hashable, Value>: @unchecked Sendable {
}
self.memoryPressure.resume()

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
registerForEnterBackground()
#endif
}
Expand All @@ -67,7 +67,7 @@ final class Cache<Key: Hashable, Value>: @unchecked Sendable {
memoryPressure.cancel()
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
private func registerForEnterBackground() {
notificationObserver = NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { [weak self] _ in
self?.clearCacheOnEnterBackground()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Internal/Graphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extension PlatformImage {

/// Decompresses the input image by drawing in the the `CGContext`.
func decompressed(isUsingPrepareForDisplay: Bool) -> PlatformImage? {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
if isUsingPrepareForDisplay, #available(iOS 15.0, tvOS 15.0, *) {
return preparingForDisplay()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Processing/ImageProcessors+CoreImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean).

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

import Foundation
import CoreImage
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Processing/ImageProcessors+GaussianBlur.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean).

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

import Foundation
import CoreImage
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Processing/ImageProcessors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension ImageProcessing where Self == ImageProcessors.Anonymous {
}
}

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

extension ImageProcessing where Self == ImageProcessors.CoreImageFilter {
/// Applies Core Image filter – `CIFilter` – to the image.
Expand Down
8 changes: 4 additions & 4 deletions Sources/NukeExtensions/ImageLoadingOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct ImageLoadingOptions {
/// Image to be displayed when the request fails. `nil` by default.
public var failureImage: PlatformImage?

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

/// The image transition animation performed when displaying a loaded image.
/// Only runs when the image was not found in memory cache. `nil` by default.
Expand Down Expand Up @@ -66,7 +66,7 @@ public struct ImageLoadingOptions {
/// request. `[]` by default.
public var processors: [any ImageProcessing] = []

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)

/// Content modes to be used for each image type (placeholder, success,
/// failure). `nil` by default (don't change content mode).
Expand Down Expand Up @@ -132,7 +132,7 @@ public struct ImageLoadingOptions {

#endif

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)

/// - parameters:
/// - placeholder: Placeholder to be displayed when the image is loading.
Expand Down Expand Up @@ -175,7 +175,7 @@ public struct ImageLoadingOptions {
public struct Transition {
var style: Style

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
enum Style { // internal representation
case fadeIn(parameters: Parameters)
case custom((ImageDisplayingView, UIImage) -> Void)
Expand Down
16 changes: 8 additions & 8 deletions Sources/NukeExtensions/ImageViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit.UIColor
import AppKit.NSImage
#endif

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

/// Displays images. Add the conformance to this protocol to your views to make
/// them compatible with Nuke image loading extensions.
Expand Down Expand Up @@ -45,7 +45,7 @@ extension Nuke_ImageDisplaying {
}
#endif

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit
/// A `UIView` that implements `ImageDisplaying` protocol.
public typealias ImageDisplayingView = UIView & Nuke_ImageDisplaying
Expand Down Expand Up @@ -198,7 +198,7 @@ private final class ImageViewController {
private var task: ImageTask?
private var options: ImageLoadingOptions

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
// Image view used for cross-fade transition between images with different
// content modes.
private lazy var transitionImageView = UIImageView()
Expand Down Expand Up @@ -245,7 +245,7 @@ private final class ImageViewController {
self.options = options

if options.isPrepareForReuseEnabled { // enabled by default
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
imageView.layer.removeAllAnimations()
#elseif os(macOS)
let layer = (imageView as? NSView)?.layer ?? imageView.layer
Expand Down Expand Up @@ -320,7 +320,7 @@ private final class ImageViewController {
display(response.container, false, .success)
}

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

private func display(_ image: ImageContainer, _ isFromMemory: Bool, _ response: ImageLoadingOptions.ResponseType) {
guard let imageView = imageView else {
Expand All @@ -329,7 +329,7 @@ private final class ImageViewController {

var image = image

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
if let tintColor = options.tintColor(for: response) {
image.image = image.image.withRenderingMode(.alwaysTemplate)
imageView.tintColor = tintColor
Expand All @@ -349,7 +349,7 @@ private final class ImageViewController {
imageView.display(image)
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
if let contentMode = options.contentMode(for: response) {
imageView.contentMode = contentMode
}
Expand All @@ -368,7 +368,7 @@ private final class ImageViewController {
// MARK: - ImageViewController (Transitions)

extension ImageViewController {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)

private func runFadeInTransition(image: ImageContainer, params: ImageLoadingOptions.Transition.Parameters, response: ImageLoadingOptions.ResponseType) {
guard let imageView = imageView else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/NukeUI/LazyImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private struct LazyImageDemoView: View {
image.resizable().aspectRatio(contentMode: .fit)
}
}
#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)
.processors(isBlured ? [ImageProcessors.GaussianBlur()] : [])
#endif
.id(imageViewId) // Example of how to implement retry
Expand All @@ -240,7 +240,7 @@ private struct LazyImageDemoView: View {
Toggle("Apply Blur", isOn: $isBlured)
}
.padding()
#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)
.background(Material.ultraThick)
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NukeUI/LazyImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public final class LazyImageView: _PlatformBaseView {
newView.isHidden = !imageView.isHidden
insertSubview(newView, at: 0)
setNeedsUpdateConstraints()
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
if let spinner = newView as? UIActivityIndicatorView {
spinner.startAnimating()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NukeVideo/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class VideoPlayerView: _PlatformBaseView {

private var _playerLayer: AVPlayerLayer?

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
override public func layoutSubviews() {
super.layoutSubviews()

Expand Down Expand Up @@ -114,7 +114,7 @@ public final class VideoPlayerView: _PlatformBaseView {
object: player?.currentItem
)

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
NotificationCenter.default.addObserver(
self,
selector: #selector(applicationWillEnterForeground),
Expand Down Expand Up @@ -173,7 +173,7 @@ public final class VideoPlayerView: _PlatformBaseView {
}
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
override public func willMove(toWindow newWindow: UIWindow?) {
if newWindow != nil && shouldResumeOnInterruption {
player?.play()
Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension ImageCaching {
#if os(macOS)
import Cocoa
typealias _ImageView = NSImageView
#elseif os(iOS) || os(tvOS)
#elseif os(iOS) || os(tvOS) || os(visionOS)
import UIKit
typealias _ImageView = UIImageView
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ImagePipelineProgressiveDecodingTests: XCTestCase {
}
}

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

@MainActor
func testParitalImagesAreDisplayed() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeExtensionsTests/ImageViewExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TVUIKit
@testable import Nuke
@testable import NukeExtensions

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

@MainActor
class ImageViewExtensionsTests: XCTestCase {
Expand Down
4 changes: 2 additions & 2 deletions Tests/NukeExtensionsTests/ImageViewIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import XCTest
@testable import Nuke
@testable import NukeExtensions

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

@MainActor
class ImageViewIntegrationTests: XCTestCase {
Expand Down Expand Up @@ -114,7 +114,7 @@ class ImageViewIntegrationTests: XCTestCase {

// MARK: - Data Passed

#if os(iOS)
#if os(iOS) || os(visionOS)
private final class MockView: UIView, Nuke_ImageDisplaying {
func nuke_display(image: PlatformImage?, data: Data?) {
recordedData.append(data)
Expand Down
6 changes: 3 additions & 3 deletions Tests/NukeExtensionsTests/ImageViewLoadingOptionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import XCTest
@testable import Nuke
@testable import NukeExtensions

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

@MainActor
class ImageViewLoadingOptionsTests: XCTestCase {
Expand Down Expand Up @@ -198,7 +198,7 @@ class ImageViewLoadingOptionsTests: XCTestCase {

#endif

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)

// MARK: - Tint Colors

Expand Down Expand Up @@ -328,7 +328,7 @@ class ImageViewLoadingOptionsTests: XCTestCase {

// MARK: - Misc

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
func testTransitionCrossDissolve() {
// GIVEN
var options = ImageLoadingOptions()
Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeExtensionsTests/NukeExtensionsTestsHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import XCTest
@testable import Nuke
@testable import NukeExtensions

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)
extension XCTestCase {
@MainActor
func expectToFinishLoadingImage(with request: ImageRequest,
Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeTests/ImageCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class ImageCacheTests: XCTestCase, @unchecked Sendable {
XCTAssertEqual(cache.totalCost, 0)
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
func testThatSomeImagesAreRemovedOnDidEnterBackground() async {
// GIVEN
cache.costLimit = Int.max
Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeTests/ImageDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ImageDecoderTests: XCTestCase {
XCTAssertNil(container.data)
}

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)
func testDecodeBaselineWebP() throws {
if #available(OSX 11.0, iOS 14.0, watchOS 7.0, tvOS 999.0, *) {
let data = Test.data(name: "baseline", extension: "webp")
Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeTests/ImageEncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class ImageEncoderTests: XCTestCase {
XCTAssertNil(AssetType(data)) // TODO: update when HEIF support is added
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)

func testEncodeCoreImageBackedImage() throws {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation
import Nuke

#if os(iOS)
#if os(iOS) || os(visionOS)

import UIKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ImagePipelineFormatsTests: XCTestCase {
let image = try XCTUnwrap(result?.value?.image)
let cgImage = try XCTUnwrap(image.cgImage)
let colorSpace = try XCTUnwrap(cgImage.colorSpace)
#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)
XCTAssertTrue(colorSpace.isWideGamutRGB)
#elseif os(watchOS)
XCTAssertFalse(colorSpace.isWideGamutRGB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class ImagePipelineProgressiveDecodingTests: XCTestCase {

// MARK: Scale

#if os(iOS)
#if os(iOS) || os(visionOS)
func testOverridingImageScaleWithFloat() throws {
// GIVEN
let request = ImageRequest(url: Test.url, userInfo: [.scaleKey: 7.0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class ImagePipelineTests: XCTestCase {
wait()
}

#if os(iOS)
#if os(iOS) || os(visionOS)
func testThumnbailIsntDecompressed() {
pipeline.configuration.imageDecompressingQueue.isSuspended = true

Expand Down
2 changes: 1 addition & 1 deletion Tests/NukeTests/ImageProcessorsTests/CircleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import XCTest
import UIKit
#endif

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
class ImageProcessorsCircleTests: XCTestCase {

func _testThatImageIsCroppedToSquareAutomatically() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import XCTest
import UIKit
#endif

#if os(iOS) || os(tvOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(macOS) || os(visionOS)

class ImageProcessorsCoreImageFilterTests: XCTestCase {
func testApplySepia() throws {
Expand Down Expand Up @@ -62,7 +62,7 @@ class ImageProcessorsCoreImageFilterTests: XCTestCase {
}
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
func testApplyFilterToCIImage() throws {
// GIVEN image backed by CIImage
let input = PlatformImage(ciImage: CIImage(cgImage: Test.image.cgImage!))
Expand Down
Loading

0 comments on commit f73c59c

Please sign in to comment.