From 7bdd017ecba2aefafc152d47bd11009fa50bf04f Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Wed, 18 Oct 2023 11:20:26 +0100 Subject: [PATCH] Fix some more Nuke things --- .../ChatChannel/ChatChannelViewModel.swift | 4 ++-- .../StreamNuke/Nuke/Decoding/ImageDecoders+Default.swift | 6 +++--- .../StreamNuke/Nuke/Decoding/ImageDecoders+Empty.swift | 4 ++-- .../StreamNuke/Nuke/Encoding/ImageEncoders+Default.swift | 2 +- .../StreamNuke/Nuke/Encoding/ImageEncoders+ImageIO.swift | 8 ++++---- .../StreamNuke/Nuke/Encoding/ImageEncoders.swift | 2 +- .../StreamNuke/Nuke/ImageContainer.swift | 4 ++-- .../StreamNuke/Nuke/Internal/Graphics.swift | 6 +++--- .../Nuke/Tasks/TaskFetchOriginalImageData.swift | 4 ++-- Sources/StreamChatSwiftUI/StreamNuke/NukeUI/Image.swift | 8 ++++---- Sources/StreamChatSwiftUI/Utils/LazyImageExtensions.swift | 2 +- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift index 5f24f94f2..dbef511fb 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift @@ -162,7 +162,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { @objc private func didReceiveMemoryWarning() { - Nuke.ImageCache.shared.removeAll() + ImageCache.shared.removeAll() messageCachingUtils.clearCache() } @@ -510,7 +510,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource { messageCachingUtils.clearCache() if messageController == nil { utils.channelControllerFactory.clearCurrentController() - Nuke.ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss) + ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss) } } } diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Default.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Default.swift index ba77bdbd7..cf19bebd8 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Default.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Default.swift @@ -59,7 +59,7 @@ extension ImageDecoders { guard let image = makeImage() else { throw ImageDecodingError.unknown } - let type = AssetType(data) + let type = NukeAssetType(data) var container = ImageContainer(image: image) container.type = type if type == .gif { @@ -78,7 +78,7 @@ extension ImageDecoders { lock.lock() defer { lock.unlock() } - let assetType = AssetType(data) + let assetType = NukeAssetType(data) if assetType == .gif { // Special handling for GIF if !isPreviewForGIFGenerated, let image = ImageDecoders.Default._decode(data, scale: scale) { isPreviewForGIFGenerated = true @@ -99,7 +99,7 @@ extension ImageDecoders { } private func isProgressiveDecodingAllowed(for data: Data) -> Bool { - let assetType = AssetType(data) + let assetType = NukeAssetType(data) // Determined whether the image supports progressive decoding or not // (only proressive JPEG is allowed for now, but you can add support diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Empty.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Empty.swift index b0feb2180..b35e3b592 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Empty.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Decoding/ImageDecoders+Empty.swift @@ -9,7 +9,7 @@ extension ImageDecoders { /// data to the image container. struct Empty: ImageDecoding, Sendable { let isProgressive: Bool - private let assetType: AssetType? + private let assetType: NukeAssetType? var isAsynchronous: Bool { false } @@ -20,7 +20,7 @@ extension ImageDecoders { /// `nil` by default. /// - isProgressive: If `false`, returns nil for every progressive /// scan. `false` by default. - init(assetType: AssetType? = nil, isProgressive: Bool = false) { + init(assetType: NukeAssetType? = nil, isProgressive: Bool = false) { self.assetType = assetType self.isProgressive = isProgressive } diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+Default.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+Default.swift index 35f205369..520fe982f 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+Default.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+Default.swift @@ -22,7 +22,7 @@ extension ImageEncoders { guard let cgImage = image.cgImage else { return nil } - let type: AssetType + let type: NukeAssetType if cgImage.isOpaque { if isHEIFPreferred && ImageEncoders.ImageIO.isSupported(type: .heic) { type = .heic diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+ImageIO.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+ImageIO.swift index d140d2a8e..0e9449261 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+ImageIO.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders+ImageIO.swift @@ -13,24 +13,24 @@ extension ImageEncoders { /// write most image file formats. This framework offers high efficiency, /// color management, and access to image metadata. struct ImageIO: ImageEncoding { - let type: AssetType + let type: NukeAssetType let compressionRatio: Float /// - parameter format: The output format. Make sure that the format is /// supported on the current hardware.s /// - parameter compressionRatio: 0.8 by default. - init(type: AssetType, compressionRatio: Float = 0.8) { + init(type: NukeAssetType, compressionRatio: Float = 0.8) { self.type = type self.compressionRatio = compressionRatio } private static let lock = NSLock() - private static var availability = [AssetType: Bool]() + private static var availability = [NukeAssetType: Bool]() /// Returns `true` if the encoding is available for the given format on /// the current hardware. Some of the most recent formats might not be /// available so its best to check before using them. - static func isSupported(type: AssetType) -> Bool { + static func isSupported(type: NukeAssetType) -> Bool { lock.lock() defer { lock.unlock() } if let isAvailable = availability[type] { diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders.swift index 397fd8875..c65837ae5 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Encoding/ImageEncoders.swift @@ -14,7 +14,7 @@ extension ImageEncoding where Self == ImageEncoders.Default { } extension ImageEncoding where Self == ImageEncoders.ImageIO { - static func imageIO(type: AssetType, compressionRatio: Float = 0.8) -> ImageEncoders.ImageIO { + static func imageIO(type: NukeAssetType, compressionRatio: Float = 0.8) -> ImageEncoders.ImageIO { ImageEncoders.ImageIO(type: type, compressionRatio: compressionRatio) } } diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/ImageContainer.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/ImageContainer.swift index ada8b1739..dabf7632a 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/ImageContainer.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/ImageContainer.swift @@ -29,7 +29,7 @@ struct ImageContainer: @unchecked Sendable { #endif /// An image type. - var type: AssetType? + var type: NukeAssetType? /// Returns `true` if the image in the container is a preview of the image. var isPreview: Bool @@ -53,7 +53,7 @@ struct ImageContainer: @unchecked Sendable { var userInfo: [UserInfoKey: Any] /// Initializes the container with the given image. - init(image: PlatformImage, type: AssetType? = nil, isPreview: Bool = false, data: Data? = nil, userInfo: [UserInfoKey: Any] = [:]) { + init(image: PlatformImage, type: NukeAssetType? = nil, isPreview: Bool = false, data: Data? = nil, userInfo: [UserInfoKey: Any] = [:]) { self.image = image self.type = type self.isPreview = isPreview diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Internal/Graphics.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Internal/Graphics.swift index 0acdcb7e0..6133dff9a 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Internal/Graphics.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Internal/Graphics.swift @@ -302,12 +302,12 @@ enum Screen { } #if os(macOS) -typealias Color = NSColor +typealias NukeColor = NSColor #else -typealias Color = UIColor +typealias NukeColor = UIColor #endif -extension Color { +extension NukeColor { /// Returns a hex representation of the color, e.g. "#FFFFAA". var hex: String { var (r, g, b, a) = (CGFloat(0), CGFloat(0), CGFloat(0), CGFloat(0)) diff --git a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Tasks/TaskFetchOriginalImageData.swift b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Tasks/TaskFetchOriginalImageData.swift index 35518ef98..4158c1b70 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Tasks/TaskFetchOriginalImageData.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/Nuke/Tasks/TaskFetchOriginalImageData.swift @@ -171,9 +171,9 @@ extension ImagePipelineTask where Value == (Data, URLResponse?) { return false } let policy = pipeline.configuration.dataCachePolicy - guard imageTasks.contains(where: { !$0.request.options.contains(.disableDiskCacheWrites) }) else { + guard imageTasks.contains(where: { !$0.request.options.contains(ImageRequest.Options.disableDiskCacheWrites) }) else { return false } - return policy == .storeOriginalData || policy == .storeAll || (policy == .automatic && imageTasks.contains { $0.request.processors.isEmpty }) + return policy == ImagePipeline.DataCachePolicy.storeOriginalData || policy == ImagePipeline.DataCachePolicy.storeAll || (policy == .automatic && imageTasks.contains { $0.request.processors.isEmpty }) } } diff --git a/Sources/StreamChatSwiftUI/StreamNuke/NukeUI/Image.swift b/Sources/StreamChatSwiftUI/StreamNuke/NukeUI/Image.swift index a6cb1756b..aec2e3141 100644 --- a/Sources/StreamChatSwiftUI/StreamNuke/NukeUI/Image.swift +++ b/Sources/StreamChatSwiftUI/StreamNuke/NukeUI/Image.swift @@ -13,7 +13,7 @@ import UIKit #if os(macOS) /// Displays images. Supports animated images and video playback. @MainActor -struct Image: NSViewRepresentable { +struct NukeImage: NSViewRepresentable { let imageContainer: ImageContainer let onCreated: ((ImageView) -> Void)? var isAnimatedImageRenderingEnabled: Bool? @@ -43,7 +43,7 @@ struct Image: NSViewRepresentable { #elseif os(iOS) || os(tvOS) /// Displays images. Supports animated images and video playback. @MainActor -struct Image: UIViewRepresentable { +struct NukeImage: UIViewRepresentable { let imageContainer: ImageContainer let onCreated: ((ImageView) -> Void)? var isAnimatedImageRenderingEnabled: Bool? @@ -52,7 +52,7 @@ struct Image: UIViewRepresentable { var resizingMode: ImageResizingMode? init(_ image: UIImage) { - self.init(ImageContainer(image: image)) + self.init(ImageContainer(image: image).image) } init(_ imageContainer: ImageContainer, onCreated: ((ImageView) -> Void)? = nil) { @@ -73,7 +73,7 @@ struct Image: UIViewRepresentable { #endif #if os(macOS) || os(iOS) || os(tvOS) -extension Image { +extension NukeImage { func updateImageView(_ imageView: ImageView) { if imageView.imageContainer?.image !== imageContainer.image { imageView.imageContainer = imageContainer diff --git a/Sources/StreamChatSwiftUI/Utils/LazyImageExtensions.swift b/Sources/StreamChatSwiftUI/Utils/LazyImageExtensions.swift index 240266f72..f64620072 100644 --- a/Sources/StreamChatSwiftUI/Utils/LazyImageExtensions.swift +++ b/Sources/StreamChatSwiftUI/Utils/LazyImageExtensions.swift @@ -6,7 +6,7 @@ import SwiftUI extension LazyImage { - public init(imageURL: URL?) where Content == NukeUI.Image { + public init(imageURL: URL?) where Content == NukeImage { let imageCDN = InjectedValues[\.utils].imageCDN guard let imageURL = imageURL else { #if COCOAPODS