소스 검색

Workaround for lazy container state resetting

onevcat 5 년 전
부모
커밋
6841ec196e
2개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      Sources/SwiftUI/ImageBinder.swift
  2. 5 0
      Sources/SwiftUI/KFImage.swift

+ 3 - 0
Sources/SwiftUI/ImageBinder.swift

@@ -48,6 +48,8 @@ extension KFImage {
 
         var isLoaded: Binding<Bool>
 
+        var loadedImage: KFCrossPlatformImage? = nil
+
         @available(*, deprecated, message: "The `options` version is deprecated And will be removed soon.")
         init(source: Source?, options: KingfisherOptionsInfo? = nil, isLoaded: Binding<Bool>) {
             self.source = source
@@ -106,6 +108,7 @@ extension KFImage {
                             // a `UIImage`)
                             // https://github.com/onevcat/Kingfisher/issues/1395
                             let image = value.image.kf.normalized
+                            self.loadedImage = image
                             let r = RetrieveImageResult(
                                 image: image, cacheType: value.cacheType, source: value.source, originalSource: value.originalSource
                             )

+ 5 - 0
Sources/SwiftUI/KFImage.swift

@@ -156,6 +156,11 @@ struct KFImageRenderer: View {
                     current, config in config(current)
                 }
                 .opacity(isLoaded ? 1.0 : 0.0)
+        } else if let image = binder.loadedImage {
+            configurations
+                .reduce(Image(crossPlatformImage: image)) {
+                    current, config in config(current)
+                }
         } else {
             Group {
                 if placeholder != nil {