Skip to content

Commit 4eb8613

Browse files
committed
Add all documentation for WebImage
1 parent d4e277f commit 4eb8613

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public struct WebImage : View {
1919

2020
@ObservedObject var imageManager: ImageManager
2121

22+
/// Create a web image with url, placeholder, custom options and context.
23+
/// - Parameter url: The image url
24+
/// - Parameter placeholder: The placeholder image to show during loading
25+
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
26+
/// - Parameter context: A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
2227
public init(url: URL?, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
2328
self.url = url
2429
self.placeholder = placeholder
@@ -62,39 +67,61 @@ extension WebImage {
6267
result.configurations.append(block)
6368
return result
6469
}
65-
70+
71+
/// Configurate this view's image with the specified cap insets and options.
72+
/// - Parameter capInsets: The values to use for the cap insets.
73+
/// - Parameter resizingMode: The resizing mode
6674
public func resizable(
6775
capInsets: EdgeInsets = EdgeInsets(),
6876
resizingMode: Image.ResizingMode = .stretch) -> WebImage
6977
{
7078
configure { $0.resizable(capInsets: capInsets, resizingMode: resizingMode) }
7179
}
72-
80+
81+
/// Configurate this view's rendering mode.
82+
/// - Parameter renderingMode: The resizing mode
7383
public func renderingMode(_ renderingMode: Image.TemplateRenderingMode?) -> WebImage {
7484
configure { $0.renderingMode(renderingMode) }
7585
}
76-
86+
87+
/// Configurate this view's image interpolation quality
88+
/// - Parameter interpolation: The interpolation quality
7789
public func interpolation(_ interpolation: Image.Interpolation) -> WebImage {
7890
configure { $0.interpolation(interpolation) }
7991
}
80-
92+
93+
/// Configurate this view's image antialiasing
94+
/// - Parameter isAntialiased: Whether or not to allow antialiasing
8195
public func antialiased(_ isAntialiased: Bool) -> WebImage {
8296
configure { $0.antialiased(isAntialiased) }
8397
}
8498
}
8599

86100
// Completion Handler
87101
extension WebImage {
102+
103+
/// Provide the action when image load fails.
104+
/// - Parameters:
105+
/// - action: The action to perform. The first arg is the error during loading. If `action` is `nil`, the call has no effect.
106+
/// - Returns: A view that triggers `action` when this image load fails.
88107
public func onFailure(perform action: ((Error) -> Void)? = nil) -> WebImage {
89108
self.imageManager.failureBlock = action
90109
return self
91110
}
92111

112+
/// Provide the action when image load successes.
113+
/// - Parameters:
114+
/// - action: The action to perform. The first arg is the loaded image, the second arg is the cache type loaded from. If `action` is `nil`, the call has no effect.
115+
/// - Returns: A view that triggers `action` when this image load successes.
93116
public func onSuccess(perform action: ((PlatformImage, SDImageCacheType) -> Void)? = nil) -> WebImage {
94117
self.imageManager.successBlock = action
95118
return self
96119
}
97120

121+
/// Provide the action when image load progress changes.
122+
/// - Parameters:
123+
/// - action: The action to perform. The first arg is the received size, the second arg is the total size, all in bytes. If `action` is `nil`, the call has no effect.
124+
/// - Returns: A view that triggers `action` when this image load successes.
98125
public func onProgress(perform action: ((Int, Int) -> Void)? = nil) -> WebImage {
99126
self.imageManager.progressBlock = action
100127
return self

0 commit comments

Comments
 (0)