Browse Source

Merge pull request #1631 from onevcat/fix/lazy-container-state

Workaround for lazy container state resetting
Wei Wang 5 years ago
parent
commit
c8d56b2ec9
2 changed files with 8 additions and 0 deletions
  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
@@ -99,6 +101,7 @@ extension KFImage {
                         self.downloadTask = nil
                         switch result {
                         case .success(let value):
+                            self.loadedImage = value.image
                             let r = RetrieveImageResult(
                                 image: value.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 {