Update the AnimatedImage with different initializer

This commit is contained in:
DreamPiggy 2019-08-07 19:45:04 +08:00
parent 1f13239f27
commit baeaa557c0
1 changed files with 27 additions and 2 deletions

View File

@ -10,17 +10,42 @@ import SwiftUI
import SDWebImage
public struct AnimatedImage: UIViewRepresentable {
public var url: URL?
var url: URL?
var name: String?
var bundle: Bundle?
var data: Data?
var scale: Length = 0
public init(url: URL?) {
self.url = url
}
public init(name: String?, bundle: Bundle? = nil) {
self.name = name
self.bundle = bundle
}
public init(data: Data, scale: Length = 0) {
self.data = data
self.scale = scale
}
public func makeUIView(context: UIViewRepresentableContext<AnimatedImage>) -> SDAnimatedImageView {
SDAnimatedImageView()
}
public func updateUIView(_ uiView: SDAnimatedImageView, context: UIViewRepresentableContext<AnimatedImage>) {
uiView.sd_setImage(with: url)
if let url = url {
uiView.sd_setImage(with: url)
return
}
if let name = name {
uiView.image = SDAnimatedImage(named: name, in: bundle, compatibleWith: nil)
return
}
if let data = data {
uiView.image = SDAnimatedImage(data: data, scale: scale)
return
}
}
}