Skip to content

Fix the support on watchOS. Using the Platform Image class instead of hard-coded SDAnimatedImage class #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions SDWebImageSwiftUI/Classes/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SDWebImage

// Data Binding Object
final class AnimatedImageModel : ObservableObject {
@Published var image: SDAnimatedImage?
@Published var image: PlatformImage?
@Published var url: URL?
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public struct AnimatedImage : ViewRepresentable {
#endif
}

public func image(_ image: SDAnimatedImage?) -> Self {
public func image(_ image: PlatformImage?) -> Self {
imageModel.image = image
return self
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public struct AnimatedImage : ViewRepresentable {
}

extension AnimatedImage {
public init(url: URL?, placeholder: SDAnimatedImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
public init(url: URL?, placeholder: PlatformImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
self.webOptions = options
self.webContext = context
self.imageModel.url = url
Expand Down
4 changes: 4 additions & 0 deletions SDWebImageSwiftUI/Classes/ImageViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation
import SDWebImage

#if !os(watchOS)

// View Wrapper
public class AnimatedImageViewWrapper : PlatformView {
var wrapped = SDAnimatedImageView()
Expand Down Expand Up @@ -59,3 +61,5 @@ extension PlatformView {

}
}

#endif
27 changes: 16 additions & 11 deletions SDWebImageSwiftUI/Classes/SDWebImageSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ import Foundation
import SwiftUI

#if os(macOS)
typealias PlatformImage = NSImage
public typealias PlatformImage = NSImage
#else
typealias PlatformImage = UIImage
#endif

#if os(macOS)
public typealias PlatformView = NSView
#else
public typealias PlatformView = UIView
public typealias PlatformImage = UIImage
#endif

extension Image {
Expand All @@ -31,14 +25,25 @@ extension Image {
}
}

#if !os(watchOS)
#if os(macOS)
public typealias PlatformView = NSView
#endif
#if os(iOS) || os(tvOS)
public typealias PlatformView = UIView
#endif
#if os(watchOS)
public typealias PlatformView = WKInterfaceObject
#endif

#if os(macOS)
typealias ViewRepresentable = NSViewRepresentable
typealias ViewRepresentableContext = NSViewRepresentableContext
#else
#endif
#if os(iOS) || os(tvOS)
typealias ViewRepresentable = UIViewRepresentable
typealias ViewRepresentableContext = UIViewRepresentableContext
#endif

#if os(watchOS)
typealias ViewRepresentable = WKInterfaceObjectRepresentable
typealias ViewRepresentableContext = WKInterfaceObjectRepresentableContext
#endif