-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathHybridWebImageFactory.swift
More file actions
48 lines (40 loc) · 1.54 KB
/
Copy pathHybridWebImageFactory.swift
File metadata and controls
48 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// HybridWebImageFactory.swift
// react-native-nitro-web-image
//
// Created by Marc Rousavy on 10.06.25.
//
import Foundation
import NitroModules
import SDWebImage
import NitroImage
class HybridWebImageFactory: HybridWebImageFactorySpec {
var maxMemoryBytes: Double {
get { Double(SDImageCacheConfig.default.maxMemoryCost) }
set { SDImageCacheConfig.default.maxMemoryCost = UInt(max(0, newValue)) }
}
func loadFromURLAsync(url urlString: String, options: AsyncImageLoadOptions?) throws -> Promise<any HybridImageSpec> {
guard let url = URL(string: urlString) else {
throw RuntimeError.error(withMessage: "URL string \"\(urlString)\" is not a valid URL!")
}
return HybridWebImageLoader.loadImage(url: url, options: options)
}
private let queue = DispatchQueue(label: "image-loader",
qos: .default,
attributes: .concurrent)
/**
* Load Image from URL
*/
func createWebImageLoader(url urlString: String, options: AsyncImageLoadOptions?) throws -> any HybridImageLoaderSpec {
guard let url = URL(string: urlString) else {
throw RuntimeError.error(withMessage: "URL string \"\(urlString)\" is not a valid URL!")
}
return HybridWebImageLoader(url: url, options: options)
}
func preload(url urlString: String) throws {
guard let url = URL(string: urlString) else {
throw RuntimeError.error(withMessage: "URL string \"\(urlString)\" is not a valid URL!")
}
SDWebImagePrefetcher.shared.prefetchURLs([url])
}
}