Skip to content

Commit

Permalink
Fix some more Nuke things
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Oct 18, 2023
1 parent 4f78d47 commit 7bdd017
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {

@objc
private func didReceiveMemoryWarning() {
Nuke.ImageCache.shared.removeAll()
ImageCache.shared.removeAll()
messageCachingUtils.clearCache()
}

Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
8 changes: 4 additions & 4 deletions Sources/StreamChatSwiftUI/StreamNuke/NukeUI/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand All @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamChatSwiftUI/Utils/LazyImageExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7bdd017

Please sign in to comment.