From 5009333792bddf293521ad9a129089f422090544 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 21 Oct 2023 16:23:18 +0800 Subject: [PATCH 1/3] 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 --- SDWebImageSwiftUI/Classes/AnimatedImage.swift | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/AnimatedImage.swift b/SDWebImageSwiftUI/Classes/AnimatedImage.swift index ef187e20..832e0328 100644 --- a/SDWebImageSwiftUI/Classes/AnimatedImage.swift +++ b/SDWebImageSwiftUI/Classes/AnimatedImage.swift @@ -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(data: data) + } context.coordinator.imageLoading.imageData = data view.wrapped.image = image } else if let url = imageModel.url { From 932b33b6bd9481c9b56843d6fdff076f93e6d15d Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 21 Sep 2023 23:26:19 +0800 Subject: [PATCH 2/3] Update the github actions --- .github/workflows/CI.yml | 2 +- .../SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8be7306b..58fa29f1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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: diff --git a/Example/SDWebImageSwiftUI.xcodeproj/xcshareddata/xcschemes/SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme b/Example/SDWebImageSwiftUI.xcodeproj/xcshareddata/xcschemes/SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme index 65df20bc..58b52ed0 100644 --- a/Example/SDWebImageSwiftUI.xcodeproj/xcshareddata/xcschemes/SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme +++ b/Example/SDWebImageSwiftUI.xcodeproj/xcshareddata/xcschemes/SDWebImageSwiftUIDemo-watchOS WatchKit App.xcscheme @@ -53,7 +53,8 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" - allowLocationSimulation = "YES"> + allowLocationSimulation = "YES" + notificationPayloadFile = "PushNotificationPayload.apns"> Date: Sat, 21 Oct 2023 16:51:21 +0800 Subject: [PATCH 3/3] Should use the SDWebImage's static image decode API instead of UIKit's one --- SDWebImageSwiftUI/Classes/AnimatedImage.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImageSwiftUI/Classes/AnimatedImage.swift b/SDWebImageSwiftUI/Classes/AnimatedImage.swift index 832e0328..6283f568 100644 --- a/SDWebImageSwiftUI/Classes/AnimatedImage.swift +++ b/SDWebImageSwiftUI/Classes/AnimatedImage.swift @@ -307,7 +307,7 @@ public struct AnimatedImage : PlatformViewRepresentable { var image: PlatformImage? = SDAnimatedImage(data: data, scale: imageModel.scale) if image == nil { // For static image, use UIImage as defaults - image = PlatformImage(data: data) + image = PlatformImage.sd_image(with: data, scale: imageModel.scale) } context.coordinator.imageLoading.imageData = data view.wrapped.image = image