123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #if canImport(SwiftUI) && canImport(Combine)
- import SwiftUI
- @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
- extension KFImage {
-
-
-
-
-
-
-
- public static func source(
- _ source: Source?, isLoaded: Binding<Bool> = .constant(false)
- ) -> KFImage
- {
- KFImage(source: source, isLoaded: isLoaded)
- }
-
-
-
-
-
-
-
- public static func resource(
- _ resource: Resource?, isLoaded: Binding<Bool> = .constant(false)
- ) -> KFImage
- {
- source(resource?.convertToSource(), isLoaded: isLoaded)
- }
-
-
-
-
-
-
-
-
-
- public static func url(
- _ url: URL?, cacheKey: String? = nil, isLoaded: Binding<Bool> = .constant(false)
- ) -> KFImage
- {
- source(url?.convertToSource(overrideCacheKey: cacheKey), isLoaded: isLoaded)
- }
-
-
-
-
-
-
-
- public static func dataProvider(
- _ provider: ImageDataProvider?, isLoaded: Binding<Bool> = .constant(false)
- ) -> KFImage
- {
- source(provider?.convertToSource(), isLoaded: isLoaded)
- }
-
-
-
-
-
-
-
-
- public static func data(
- _ data: Data?, cacheKey: String, isLoaded: Binding<Bool> = .constant(false)
- ) -> KFImage
- {
- if let data = data {
- return dataProvider(RawImageDataProvider(data: data, cacheKey: cacheKey), isLoaded: isLoaded)
- } else {
- return dataProvider(nil, isLoaded: isLoaded)
- }
- }
- }
- @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
- extension KFImage {
-
-
-
- public func placeholder<Content: View>(@ViewBuilder _ content: () -> Content) -> KFImage {
- let v = content()
- var result = self
- result.context.placeholder = AnyView(v)
- return result
- }
-
-
-
- public func cancelOnDisappear(_ flag: Bool) -> KFImage {
- var result = self
- result.context.cancelOnDisappear = flag
- return result
- }
-
-
-
-
-
-
-
-
- public func fade(duration: TimeInterval) -> KFImage {
- context.binder.options.transition = .fade(duration)
- return self
- }
- }
- #endif
|