Skip to content

Commit 5009333

Browse files
committed
Allows to use UIImage/NSImage as defaults when init the AnimatedImage with JPEG data
This match the behavior when passing with the JPEG url initializer
1 parent 86b1901 commit 5009333

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

+17-3
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,29 @@ public struct AnimatedImage : PlatformViewRepresentable {
286286
// Refresh image, imageModel is the Source of Truth, switch the type
287287
// Although we have Source of Truth, we can check the previous value, to avoid re-generate SDAnimatedImage, which is performance-cost.
288288
if let name = imageModel.name, name != context.coordinator.imageLoading.imageName {
289+
var image: PlatformImage?
289290
#if os(macOS)
290-
let image = SDAnimatedImage(named: name, in: imageModel.bundle)
291+
image = SDAnimatedImage(named: name, in: imageModel.bundle)
292+
if image == nil {
293+
// For static image, use NSImage as defaults
294+
let bundle = imageModel.bundle ?? .main
295+
image = bundle.image(forResource: name)
296+
}
291297
#else
292-
let image = SDAnimatedImage(named: name, in: imageModel.bundle, compatibleWith: nil)
298+
image = SDAnimatedImage(named: name, in: imageModel.bundle, compatibleWith: nil)
299+
if image == nil {
300+
// For static image, use UIImage as defaults
301+
image = PlatformImage(named: name, in: imageModel.bundle, compatibleWith: nil)
302+
}
293303
#endif
294304
context.coordinator.imageLoading.imageName = name
295305
view.wrapped.image = image
296306
} else if let data = imageModel.data, data != context.coordinator.imageLoading.imageData {
297-
let image = SDAnimatedImage(data: data, scale: imageModel.scale)
307+
var image: PlatformImage? = SDAnimatedImage(data: data, scale: imageModel.scale)
308+
if image == nil {
309+
// For static image, use UIImage as defaults
310+
image = PlatformImage(data: data)
311+
}
298312
context.coordinator.imageLoading.imageData = data
299313
view.wrapped.image = image
300314
} else if let url = imageModel.url {

0 commit comments

Comments
 (0)