Skip to content

Commit 9709389

Browse files
committed
Fix the support on watchOS. Using the Platform Image class instead of hard-coded SDAnimatedImage class
1 parent 0897944 commit 9709389

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import SDWebImage
1313

1414
// Data Binding Object
1515
final class AnimatedImageModel : ObservableObject {
16-
@Published var image: SDAnimatedImage?
16+
@Published var image: PlatformImage?
1717
@Published var url: URL?
1818
}
1919

@@ -146,7 +146,7 @@ public struct AnimatedImage : ViewRepresentable {
146146
#endif
147147
}
148148

149-
public func image(_ image: SDAnimatedImage?) -> Self {
149+
public func image(_ image: PlatformImage?) -> Self {
150150
imageModel.image = image
151151
return self
152152
}
@@ -202,7 +202,7 @@ public struct AnimatedImage : ViewRepresentable {
202202
}
203203

204204
extension AnimatedImage {
205-
public init(url: URL?, placeholder: SDAnimatedImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
205+
public init(url: URL?, placeholder: PlatformImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
206206
self.webOptions = options
207207
self.webContext = context
208208
self.imageModel.url = url

SDWebImageSwiftUI/Classes/ImageViewWrapper.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import Foundation
1010
import SDWebImage
1111

12+
#if !os(watchOS)
13+
1214
// View Wrapper
1315
public class AnimatedImageViewWrapper : PlatformView {
1416
var wrapped = SDAnimatedImageView()
@@ -59,3 +61,5 @@ extension PlatformView {
5961

6062
}
6163
}
64+
65+
#endif

SDWebImageSwiftUI/Classes/SDWebImageSwiftUI.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ import Foundation
1010
import SwiftUI
1111

1212
#if os(macOS)
13-
typealias PlatformImage = NSImage
13+
public typealias PlatformImage = NSImage
1414
#else
15-
typealias PlatformImage = UIImage
16-
#endif
17-
18-
#if os(macOS)
19-
public typealias PlatformView = NSView
20-
#else
21-
public typealias PlatformView = UIView
15+
public typealias PlatformImage = UIImage
2216
#endif
2317

2418
extension Image {
@@ -31,14 +25,25 @@ extension Image {
3125
}
3226
}
3327

34-
#if !os(watchOS)
28+
#if os(macOS)
29+
public typealias PlatformView = NSView
30+
#endif
31+
#if os(iOS) || os(tvOS)
32+
public typealias PlatformView = UIView
33+
#endif
34+
#if os(watchOS)
35+
public typealias PlatformView = WKInterfaceObject
36+
#endif
3537

3638
#if os(macOS)
3739
typealias ViewRepresentable = NSViewRepresentable
3840
typealias ViewRepresentableContext = NSViewRepresentableContext
39-
#else
41+
#endif
42+
#if os(iOS) || os(tvOS)
4043
typealias ViewRepresentable = UIViewRepresentable
4144
typealias ViewRepresentableContext = UIViewRepresentableContext
4245
#endif
43-
46+
#if os(watchOS)
47+
typealias ViewRepresentable = WKInterfaceObjectRepresentable
48+
typealias ViewRepresentableContext = WKInterfaceObjectRepresentableContext
4449
#endif

0 commit comments

Comments
 (0)