Skip to content

Commit 5c6bfdf

Browse files
authored
Merge pull request #277 from SDWebImage/bugfix/jpeg_animatedimage_data
Allows to use UIImage/NSImage as defaults when init the AnimatedImage with JPEG data
2 parents 86b1901 + 9cf058e commit 5c6bfdf

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Diff for: .github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
matrix:
4747
iosDestination: ["name=iPhone 13 Pro"]
4848
tvOSDestination: ["name=Apple TV"]
49-
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 - 45mm"]
49+
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 (45mm)"]
5050
macOSDestination: ["platform=macOS"]
5151
macCatalystDestination: ["platform=macOS,arch=x86_64,variant=Mac Catalyst"]
5252
steps:

Diff for: Example/SDWebImageSwiftUI.xcodeproj/xcshareddata/xcschemes/SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
ignoresPersistentStateOnLaunch = "NO"
5454
debugDocumentVersioning = "YES"
5555
debugServiceExtension = "internal"
56-
allowLocationSimulation = "YES">
56+
allowLocationSimulation = "YES"
57+
notificationPayloadFile = "PushNotificationPayload.apns">
5758
<BuildableProductRunnable
5859
runnableDebuggingMode = "0">
5960
<BuildableReference

Diff for: 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.sd_image(with: data, scale: imageModel.scale)
311+
}
298312
context.coordinator.imageLoading.imageData = data
299313
view.wrapped.image = image
300314
} else if let url = imageModel.url {

0 commit comments

Comments
 (0)