Add support for AnimatedImage to load indicator and transition, by using SDWebImage's already supported features

This commit is contained in:
DreamPiggy 2019-10-25 14:54:09 +08:00
parent c99f5c6474
commit cbe282b69c
1 changed files with 25 additions and 0 deletions

View File

@ -36,6 +36,9 @@ final class AnimatedImageConfiguration: ObservableObject {
@Published var incrementalLoad: Bool?
@Published var maxBufferSize: UInt?
@Published var customLoopCount: Int?
// These configurations only useful for web image loading
@Published var indicator: SDWebImageIndicator?
@Published var transition: SDWebImageTransition?
}
// Convenient
@ -203,6 +206,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
#endif
} else {
if let url = url {
view.wrapped.sd_imageIndicator = imageConfiguration.indicator
view.wrapped.sd_imageTransition = imageConfiguration.transition
loadImage(view, url: url)
}
}
@ -545,6 +550,26 @@ extension AnimatedImage {
}
}
// Web Image convenience
extension AnimatedImage {
/// Associate a indicator when loading image with url
/// - Note: If you do not need indicator, specify nil. Defaults to nil
/// - Parameter indicator: indicator, see more in `SDWebImageIndicator`
public func indicator(_ indicator: SDWebImageIndicator?) -> AnimatedImage {
imageConfiguration.indicator = indicator
return self
}
/// Associate a transition when loading image with url
/// - Note: If you specify nil, do not do transition. Defautls to nil.
/// - Parameter transition: transition, see more in `SDWebImageTransition`
public func transition(_ transition: SDWebImageTransition?) -> AnimatedImage {
imageConfiguration.transition = transition
return self
}
}
#if DEBUG
struct AnimatedImage_Previews : PreviewProvider {
static var previews: some View {