Skip to content

Allows to use UIImage/NSImage as defaults when init the AnimatedImage with JPEG data #277

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 3 commits into from
Oct 21, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
matrix:
iosDestination: ["name=iPhone 13 Pro"]
tvOSDestination: ["name=Apple TV"]
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 - 45mm"]
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 (45mm)"]
macOSDestination: ["platform=macOS"]
macCatalystDestination: ["platform=macOS,arch=x86_64,variant=Mac Catalyst"]
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
allowLocationSimulation = "YES"
notificationPayloadFile = "PushNotificationPayload.apns">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
Expand Down
20 changes: 17 additions & 3 deletions SDWebImageSwiftUI/Classes/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,29 @@ public struct AnimatedImage : PlatformViewRepresentable {
// Refresh image, imageModel is the Source of Truth, switch the type
// Although we have Source of Truth, we can check the previous value, to avoid re-generate SDAnimatedImage, which is performance-cost.
if let name = imageModel.name, name != context.coordinator.imageLoading.imageName {
var image: PlatformImage?
#if os(macOS)
let image = SDAnimatedImage(named: name, in: imageModel.bundle)
image = SDAnimatedImage(named: name, in: imageModel.bundle)
if image == nil {
// For static image, use NSImage as defaults
let bundle = imageModel.bundle ?? .main
image = bundle.image(forResource: name)
}
#else
let image = SDAnimatedImage(named: name, in: imageModel.bundle, compatibleWith: nil)
image = SDAnimatedImage(named: name, in: imageModel.bundle, compatibleWith: nil)
if image == nil {
// For static image, use UIImage as defaults
image = PlatformImage(named: name, in: imageModel.bundle, compatibleWith: nil)
}
#endif
context.coordinator.imageLoading.imageName = name
view.wrapped.image = image
} else if let data = imageModel.data, data != context.coordinator.imageLoading.imageData {
let image = SDAnimatedImage(data: data, scale: imageModel.scale)
var image: PlatformImage? = SDAnimatedImage(data: data, scale: imageModel.scale)
if image == nil {
// For static image, use UIImage as defaults
image = PlatformImage.sd_image(with: data, scale: imageModel.scale)
}
context.coordinator.imageLoading.imageData = data
view.wrapped.image = image
} else if let url = imageModel.url {
Expand Down