Skip to content

Commit 739d80f

Browse files
authored
Merge pull request #15 from SDWebImage/fix_api_documentation
Complete all current API documentation
2 parents df7728d + 4eb8613 commit 739d80f

File tree

2 files changed

+124
-10
lines changed

2 files changed

+124
-10
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,21 @@ public struct AnimatedImage : PlatformViewRepresentable {
5252
/// True to start animation, false to stop animation.
5353
@Binding public var isAnimating: Bool
5454

55+
/// Create an animated image with url, placeholder, custom options and context.
56+
/// - Parameter url: The image url
57+
/// - Parameter placeholder: The placeholder image to show during loading
58+
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
59+
/// - 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.
5560
public init(url: URL?, placeholder: PlatformImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
5661
self.init(url: url, placeholder: placeholder, options: options, context: context, isAnimating: .constant(true))
5762
}
5863

64+
/// Create an animated image with url, placeholder, custom options and context, including animation control binding.
65+
/// - Parameter url: The image url
66+
/// - Parameter placeholder: The placeholder image to show during loading
67+
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
68+
/// - 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.
69+
/// - Parameter isAnimating: The binding for animation control
5970
public init(url: URL?, placeholder: PlatformImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool>) {
6071
self._isAnimating = isAnimating
6172
self.placeholder = placeholder
@@ -64,10 +75,19 @@ public struct AnimatedImage : PlatformViewRepresentable {
6475
self.imageModel.url = url
6576
}
6677

78+
/// Create an animated image with name and bundle.
79+
/// - Note: Asset Catalog is not supported.
80+
/// - Parameter name: The image name
81+
/// - Parameter bundle: The bundle contains image
6782
public init(name: String, bundle: Bundle? = nil) {
6883
self.init(name: name, bundle: bundle, isAnimating: .constant(true))
6984
}
70-
85+
86+
/// Create an animated image with name and bundle, including animation control binding.
87+
/// - Note: Asset Catalog is not supported.
88+
/// - Parameter name: The image name
89+
/// - Parameter bundle: The bundle contains image
90+
/// - Parameter isAnimating: The binding for animation control
7191
public init(name: String, bundle: Bundle? = nil, isAnimating: Binding<Bool>) {
7292
self._isAnimating = isAnimating
7393
#if os(macOS)
@@ -77,11 +97,18 @@ public struct AnimatedImage : PlatformViewRepresentable {
7797
#endif
7898
self.imageModel.image = image
7999
}
80-
100+
101+
/// Create an animated image with data and scale.
102+
/// - Parameter data: The image data
103+
/// - Parameter scale: The scale factor
81104
public init(data: Data, scale: CGFloat = 0) {
82105
self.init(data: data, scale: scale, isAnimating: .constant(true))
83106
}
84107

108+
/// Create an animated image with data and scale, including animation control binding.
109+
/// - Parameter data: The image data
110+
/// - Parameter scale: The scale factor
111+
/// - Parameter isAnimating: The binding for animation control
85112
public init(data: Data, scale: CGFloat = 0, isAnimating: Binding<Bool>) {
86113
self._isAnimating = isAnimating
87114
let image = SDAnimatedImage(data: data, scale: scale)
@@ -281,6 +308,11 @@ public struct AnimatedImage : PlatformViewRepresentable {
281308

282309
// Layout
283310
extension AnimatedImage {
311+
312+
/// Configurate this view's image with the specified cap insets and options.
313+
/// - Warning: Animated Image does not implementes.
314+
/// - Parameter capInsets: The values to use for the cap insets.
315+
/// - Parameter resizingMode: The resizing mode
284316
public func resizable(
285317
capInsets: EdgeInsets = EdgeInsets(),
286318
resizingMode: Image.ResizingMode = .stretch) -> AnimatedImage
@@ -289,28 +321,51 @@ extension AnimatedImage {
289321
imageLayout.resizingMode = resizingMode
290322
return self
291323
}
292-
324+
325+
/// Configurate this view's rendering mode.
326+
/// - Warning: Animated Image does not implementes.
327+
/// - Parameter renderingMode: The resizing mode
293328
public func renderingMode(_ renderingMode: Image.TemplateRenderingMode?) -> AnimatedImage {
294329
imageLayout.renderingMode = renderingMode
295330
return self
296331
}
297-
332+
333+
/// Configurate this view's image interpolation quality
334+
/// - Parameter interpolation: The interpolation quality
298335
public func interpolation(_ interpolation: Image.Interpolation) -> AnimatedImage {
299336
imageLayout.interpolation = interpolation
300337
return self
301338
}
302-
339+
340+
/// Configurate this view's image antialiasing
341+
/// - Parameter isAntialiased: Whether or not to allow antialiasing
303342
public func antialiased(_ isAntialiased: Bool) -> AnimatedImage {
304343
imageLayout.antialiased = isAntialiased
305344
return self
306345
}
307-
346+
/// Constrains this view's dimensions to the specified aspect ratio.
347+
/// - Parameters:
348+
/// - aspectRatio: The ratio of width to height to use for the resulting
349+
/// view. If `aspectRatio` is `nil`, the resulting view maintains this
350+
/// view's aspect ratio.
351+
/// - contentMode: A flag indicating whether this view should fit or
352+
/// fill the parent context.
353+
/// - Returns: A view that constrains this view's dimensions to
354+
/// `aspectRatio`, using `contentMode` as its scaling algorithm.
308355
public func aspectRatio(_ aspectRatio: CGFloat? = nil, contentMode: ContentMode) -> AnimatedImage {
309356
imageLayout.aspectRatio = aspectRatio
310357
imageLayout.contentMode = contentMode
311358
return self
312359
}
313360

361+
/// Constrains this view's dimensions to the aspect ratio of the given size.
362+
/// - Parameters:
363+
/// - aspectRatio: A size specifying the ratio of width to height to use
364+
/// for the resulting view.
365+
/// - contentMode: A flag indicating whether this view should fit or
366+
/// fill the parent context.
367+
/// - Returns: A view that constrains this view's dimensions to
368+
/// `aspectRatio`, using `contentMode` as its scaling algorithm.
314369
public func aspectRatio(_ aspectRatio: CGSize, contentMode: ContentMode) -> AnimatedImage {
315370
var ratio: CGFloat?
316371
if aspectRatio.width > 0 && aspectRatio.height > 0 {
@@ -319,27 +374,46 @@ extension AnimatedImage {
319374
return self.aspectRatio(ratio, contentMode: contentMode)
320375
}
321376

377+
/// Scales this view to fit its parent.
378+
/// - Returns: A view that scales this view to fit its parent,
379+
/// maintaining this view's aspect ratio.
322380
public func scaledToFit() -> AnimatedImage {
323381
self.aspectRatio(nil, contentMode: .fit)
324382
}
325383

384+
/// Scales this view to fill its parent.
385+
/// - Returns: A view that scales this view to fit its parent,
386+
/// maintaining this view's aspect ratio.
326387
public func scaledToFill() -> AnimatedImage {
327388
self.aspectRatio(nil, contentMode: .fill)
328389
}
329390
}
330391

331392
// AnimatedImage Modifier
332393
extension AnimatedImage {
394+
395+
/// Total loop count for animated image rendering. Defaults to nil.
396+
/// - Note: Pass nil to disable customization, use the image itself loop count (`animatedImageLoopCount`) instead
397+
/// - Parameter loopCount: The animation loop count
333398
public func customLoopCount(_ loopCount: Int?) -> AnimatedImage {
334399
imageConfiguration.customLoopCount = loopCount
335400
return self
336401
}
337402

403+
/// Provide a max buffer size by bytes. This is used to adjust frame buffer count and can be useful when the decoding cost is expensive (such as Animated WebP software decoding). Default is nil.
404+
// `0` or nil means automatically adjust by calculating current memory usage.
405+
// `1` means without any buffer cache, each of frames will be decoded and then be freed after rendering. (Lowest Memory and Highest CPU)
406+
// `UInt.max` means cache all the buffer. (Lowest CPU and Highest Memory)
407+
/// - Parameter bufferSize: The max buffer size
338408
public func maxBufferSize(_ bufferSize: UInt?) -> AnimatedImage {
339409
imageConfiguration.maxBufferSize = bufferSize
340410
return self
341411
}
342412

413+
/// Whehter or not to enable incremental image load for animated image. See `SDAnimatedImageView` for detailed explanation for this.
414+
/// - Note: If you are confused about this description, open Chrome browser to view some large GIF images with low network speed to see the animation behavior.
415+
/// Default is true. Set to false to only render the static poster for incremental animated image.
416+
/// - Parameter incrementalLoad: Whether or not to incremental load
343417
public func incrementalLoad(_ incrementalLoad: Bool) -> AnimatedImage {
344418
imageConfiguration.incrementalLoad = incrementalLoad
345419
return self
@@ -348,16 +422,29 @@ extension AnimatedImage {
348422

349423
// Completion Handler
350424
extension AnimatedImage {
425+
426+
/// Provide the action when image load fails.
427+
/// - Parameters:
428+
/// - action: The action to perform. The first arg is the error during loading. If `action` is `nil`, the call has no effect.
429+
/// - Returns: A view that triggers `action` when this image load fails.
351430
public func onFailure(perform action: ((Error) -> Void)? = nil) -> AnimatedImage {
352431
imageModel.failureBlock = action
353432
return self
354433
}
355434

435+
/// Provide the action when image load successes.
436+
/// - Parameters:
437+
/// - 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.
438+
/// - Returns: A view that triggers `action` when this image load successes.
356439
public func onSuccess(perform action: ((PlatformImage, SDImageCacheType) -> Void)? = nil) -> AnimatedImage {
357440
imageModel.successBlock = action
358441
return self
359442
}
360443

444+
/// Provide the action when image load progress changes.
445+
/// - Parameters:
446+
/// - 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.
447+
/// - Returns: A view that triggers `action` when this image load successes.
361448
public func onProgress(perform action: ((Int, Int) -> Void)? = nil) -> AnimatedImage {
362449
imageModel.progressBlock = action
363450
return self

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)