Skip to content

Commit fc9c2b5

Browse files
committed
Change the AnimatedImage API to match the same design. But AnimatedImage need the platform image (becaseu this is needed for SD and return type is limited to AnimatedImage)
1 parent df96e83 commit fc9c2b5

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class AnimatedImageConfiguration: ObservableObject {
4747
@Published var indicator: SDWebImageIndicator?
4848
@Published var transition: SDWebImageTransition?
4949
#endif
50+
@Published var placeholder: PlatformImage?
5051
}
5152

5253
// Convenient
@@ -67,7 +68,6 @@ public struct AnimatedImage : PlatformViewRepresentable {
6768
@ObservedObject var imageCoordinator = AnimatedImageCoordinator()
6869

6970
var url: URL?
70-
var placeholder: PlatformImage?
7171
var webOptions: SDWebImageOptions = []
7272
var webContext: [SDWebImageContextOption : Any]? = nil
7373

@@ -80,8 +80,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
8080
/// - Parameter placeholder: The placeholder image to show during loading
8181
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
8282
/// - 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.
83-
public init(url: URL?, placeholder: PlatformImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
84-
self.init(url: url, placeholder: placeholder, options: options, context: context, isAnimating: .constant(true))
83+
public init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
84+
self.init(url: url, options: options, context: context, isAnimating: .constant(true))
8585
}
8686

8787
/// Create an animated image with url, placeholder, custom options and context, including animation control binding.
@@ -90,9 +90,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
9090
/// - Parameter options: The options to use when downloading the image. See `SDWebImageOptions` for the possible values.
9191
/// - 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.
9292
/// - Parameter isAnimating: The binding for animation control
93-
public init(url: URL?, placeholder: PlatformImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool>) {
93+
public init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, isAnimating: Binding<Bool>) {
9494
self._isAnimating = isAnimating
95-
self.placeholder = placeholder
9695
self.webOptions = options
9796
self.webContext = context
9897
self.url = url
@@ -190,7 +189,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
190189
if currentOperation != nil {
191190
return
192191
}
193-
view.wrapped.sd_setImage(with: url, placeholderImage: placeholder, options: webOptions, context: webContext, progress: { (receivedSize, expectedSize, _) in
192+
view.wrapped.sd_setImage(with: url, placeholderImage: imageConfiguration.placeholder, options: webOptions, context: webContext, progress: { (receivedSize, expectedSize, _) in
194193
self.imageModel.progressBlock?(receivedSize, expectedSize)
195194
}) { (image, error, cacheType, _) in
196195
if let image = image {
@@ -652,10 +651,17 @@ extension AnimatedImage {
652651
}
653652
}
654653

655-
#if os(macOS) || os(iOS) || os(tvOS)
656654
// Web Image convenience
657655
extension AnimatedImage {
658656

657+
/// Associate a placeholder when loading image with url
658+
/// - Parameter content: A view that describes the placeholder.
659+
public func placeholder(_ placeholder: PlatformImage?) -> AnimatedImage {
660+
imageConfiguration.placeholder = placeholder
661+
return self
662+
}
663+
664+
#if os(macOS) || os(iOS) || os(tvOS)
659665
/// Associate a indicator when loading image with url
660666
/// - Note: If you do not need indicator, specify nil. Defaults to nil
661667
/// - Parameter indicator: indicator, see more in `SDWebImageIndicator`
@@ -671,8 +677,8 @@ extension AnimatedImage {
671677
imageConfiguration.transition = transition
672678
return self
673679
}
680+
#endif
674681
}
675-
#endif
676682

677683
#if DEBUG
678684
struct AnimatedImage_Previews : PreviewProvider {

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extension WebImage {
138138
}
139139
}
140140

141-
// Custom Configuration
141+
// WebImage Modifier
142142
extension WebImage {
143143

144144
/// Associate a placeholder when loading image with url

0 commit comments

Comments
 (0)