File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
SDWebImageSwiftUI/Classes Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -10,17 +10,42 @@ import SwiftUI
10
10
import SDWebImage
11
11
12
12
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
14
18
15
19
public init ( url: URL ? ) {
16
20
self . url = url
17
21
}
18
22
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
+
19
33
public func makeUIView( context: UIViewRepresentableContext < AnimatedImage > ) -> SDAnimatedImageView {
20
34
SDAnimatedImageView ( )
21
35
}
22
36
23
37
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
+ }
25
50
}
26
51
}
You can’t perform that action at this time.
0 commit comments