Skip to content

Commit baeaa55

Browse files
committed
Update the AnimatedImage with different initializer
1 parent 1f13239 commit baeaa55

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,42 @@ import SwiftUI
1010
import SDWebImage
1111

1212
public struct AnimatedImage: UIViewRepresentable {
13-
public var url: URL?
13+
var url: URL?
14+
var name: String?
15+
var bundle: Bundle?
16+
var data: Data?
17+
var scale: Length = 0
1418

1519
public init(url: URL?) {
1620
self.url = url
1721
}
1822

23+
public init(name: String?, bundle: Bundle? = nil) {
24+
self.name = name
25+
self.bundle = bundle
26+
}
27+
28+
public init(data: Data, scale: Length = 0) {
29+
self.data = data
30+
self.scale = scale
31+
}
32+
1933
public func makeUIView(context: UIViewRepresentableContext<AnimatedImage>) -> SDAnimatedImageView {
2034
SDAnimatedImageView()
2135
}
2236

2337
public func updateUIView(_ uiView: SDAnimatedImageView, context: UIViewRepresentableContext<AnimatedImage>) {
24-
uiView.sd_setImage(with: url)
38+
if let url = url {
39+
uiView.sd_setImage(with: url)
40+
return
41+
}
42+
if let name = name {
43+
uiView.image = SDAnimatedImage(named: name, in: bundle, compatibleWith: nil)
44+
return
45+
}
46+
if let data = data {
47+
uiView.image = SDAnimatedImage(data: data, scale: scale)
48+
return
49+
}
2550
}
2651
}

0 commit comments

Comments
 (0)