Skip to content

Commit

Permalink
Add watchOS support in KingfisherHasImageComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed May 4, 2024
1 parent 5d2bea8 commit 4298e26
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Sources/Extensions/HasImageComponent+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extension NSTabViewItem: KingfisherHasImageComponent {}
extension NSStatusItem: KingfisherHasImageComponent {}

extension NSCell: KingfisherHasImageComponent {}

#endif

#if canImport(UIKit) && !os(watchOS)
Expand All @@ -66,7 +65,16 @@ extension UIBarItem: KingfisherHasImageComponent {}

#endif

#if !os(watchOS)
#if canImport(WatchKit)
import WatchKit
extension WKInterfaceImage: KingfisherHasImageComponent {
@MainActor public var image: KFCrossPlatformImage? {
get { nil }
set { setImage(newValue) }
}
}
#endif

@MainActor
extension KingfisherWrapper where Base: KingfisherHasImageComponent {

Expand Down Expand Up @@ -340,9 +348,14 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {

var options = parsedOptions

if !options.keepCurrentImageWhileLoading || base.image == nil {
// Always set placeholder while there is no image/placeholder yet.
mutatingSelf.base.image = placeholder
// Always set placeholder while there is no image/placeholder yet.
#if os(watchOS)
let usePlaceholderDuringLoading = !options.keepCurrentImageWhileLoading
#else
let usePlaceholderDuringLoading = !options.keepCurrentImageWhileLoading || base.image == nil
#endif
if usePlaceholderDuringLoading {
base.image = placeholder
}

let issuedIdentifier = Source.Identifier.next()
Expand Down Expand Up @@ -428,5 +441,3 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {
set { setRetainedAssociatedObject(base, &imageTaskKey, newValue)}
}
}

#endif

0 comments on commit 4298e26

Please sign in to comment.