Quellcode durchsuchen

Add documentation for startLoadingBeforeViewAppear

onevcat vor 3 Jahren
Ursprung
Commit
ef64d51876
2 geänderte Dateien mit 16 neuen und 2 gelöschten Zeilen
  1. 1 2
      Sources/General/KFOptionsSetter.swift
  2. 15 0
      Sources/SwiftUI/KFImageOptions.swift

+ 1 - 2
Sources/General/KFOptionsSetter.swift

@@ -442,8 +442,7 @@ extension KFOptionSetter {
     ///                         to form a processor pipeline.
     /// - Returns: A `Self` value with changes applied.
     ///
-    /// - Note:
-    /// To append processors to current ones instead of replacing them all, concatenate them by `|>`, then use
+    /// - Note: To append processors to current ones instead of replacing them all, concatenate them by `|>`, then use
     /// `appendProcessor(_:)`.
     public func setProcessors(_ processors: [ImageProcessor]) -> Self {
         switch processors.count {

+ 15 - 0
Sources/SwiftUI/KFImageOptions.swift

@@ -135,6 +135,21 @@ extension KFImageProtocol {
         return self
     }
     
+    /// Sets whether to start the image loading before the view actually appears.
+    ///
+    /// By default, Kingfisher performs a lazy loading for `KFImage`. The image loading won't start until the view's
+    /// `onAppear` is called. However, sometimes you may want to trigger an aggressive loading for the view. By enabling
+    /// this, the `KFImage` will try to load the view when its `body` is evaluated when the image loading is not yet
+    /// started or a previous loading did fail.
+    ///
+    /// - Parameter flag: Whether the image loading should happen before view appear. Default is `true`.
+    /// - Returns: A `KFImage` with changes applied.
+    ///
+    /// - Note: This is a temporary workaround for an issue from iOS 16, where the SwiftUI view's `onAppear` is not
+    /// called when it is deeply embedded inside a `List` or `ForEach`.
+    /// See [#1988](https://github.com/onevcat/Kingfisher/issues/1988). It may cause performance regression, especially
+    /// if you have a lot of images to load in the view. Use it as your own risk.
+    ///
     public func startLoadingBeforeViewAppear(_ flag: Bool = true) -> Self {
         context.startLoadingBeforeViewAppear = flag
         return self