From a448bbe47d3aa626cb10df8a41cc0ec3544701c1 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 29 Nov 2023 01:18:37 +0800 Subject: [PATCH 1/5] Update the AnimatedImage API to expose the SDAnimatedImageView This is not necessary to hide the details and use UIView super view --- SDWebImageSwiftUI/Classes/AnimatedImage.swift | 12 ++++++------ SDWebImageSwiftUI/Classes/ImageViewWrapper.swift | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/AnimatedImage.swift b/SDWebImageSwiftUI/Classes/AnimatedImage.swift index 48f8f30..1a6adbf 100644 --- a/SDWebImageSwiftUI/Classes/AnimatedImage.swift +++ b/SDWebImageSwiftUI/Classes/AnimatedImage.swift @@ -66,8 +66,8 @@ final class AnimatedImageHandler: ObservableObject { @Published var failureBlock: ((Error) -> Void)? @Published var progressBlock: ((Int, Int) -> Void)? // Coordinator Handler - @Published var viewCreateBlock: ((PlatformView, AnimatedImage.Context) -> Void)? - @Published var viewUpdateBlock: ((PlatformView, AnimatedImage.Context) -> Void)? + @Published var viewCreateBlock: ((SDAnimatedImageView, AnimatedImage.Context) -> Void)? + @Published var viewUpdateBlock: ((SDAnimatedImageView, AnimatedImage.Context) -> Void)? } /// Layout Binding Object, supports dynamic @State changes @@ -109,7 +109,7 @@ public struct AnimatedImage : PlatformViewRepresentable { /// A observed object to pass through the image manager loading status to indicator @ObservedObject var indicatorStatus = IndicatorStatus() - static var viewDestroyBlock: ((PlatformView, Coordinator) -> Void)? + static var viewDestroyBlock: ((SDAnimatedImageView, Coordinator) -> Void)? /// A Binding to control the animation. You can bind external logic to control the animation status. /// True to start animation, false to stop animation. @@ -770,7 +770,7 @@ extension AnimatedImage { /// Provide the action when view representable create the native view. /// - Parameter action: The action to perform. The first arg is the native view. The seconds arg is the context. /// - Returns: A view that triggers `action` when view representable create the native view. - public func onViewCreate(perform action: ((PlatformView, Context) -> Void)? = nil) -> AnimatedImage { + public func onViewCreate(perform action: ((SDAnimatedImageView, Context) -> Void)? = nil) -> AnimatedImage { self.imageHandler.viewCreateBlock = action return self } @@ -778,7 +778,7 @@ extension AnimatedImage { /// Provide the action when view representable update the native view. /// - Parameter action: The action to perform. The first arg is the native view. The seconds arg is the context. /// - Returns: A view that triggers `action` when view representable update the native view. - public func onViewUpdate(perform action: ((PlatformView, Context) -> Void)? = nil) -> AnimatedImage { + public func onViewUpdate(perform action: ((SDAnimatedImageView, Context) -> Void)? = nil) -> AnimatedImage { self.imageHandler.viewUpdateBlock = action return self } @@ -786,7 +786,7 @@ extension AnimatedImage { /// Provide the action when view representable destroy the native view /// - Parameter action: The action to perform. The first arg is the native view. The seconds arg is the coordinator (with userInfo). /// - Returns: A view that triggers `action` when view representable destroy the native view. - public static func onViewDestroy(perform action: ((PlatformView, Coordinator) -> Void)? = nil) { + public static func onViewDestroy(perform action: ((SDAnimatedImageView, Coordinator) -> Void)? = nil) { self.viewDestroyBlock = action } } diff --git a/SDWebImageSwiftUI/Classes/ImageViewWrapper.swift b/SDWebImageSwiftUI/Classes/ImageViewWrapper.swift index 68b12af..b0d6ac3 100644 --- a/SDWebImageSwiftUI/Classes/ImageViewWrapper.swift +++ b/SDWebImageSwiftUI/Classes/ImageViewWrapper.swift @@ -14,12 +14,13 @@ import SDWebImage /// Use wrapper to solve tne `UIImageView`/`NSImageView` frame size become image size issue (SwiftUI's Bug) @available(iOS 14.0, OSX 11.0, tvOS 14.0, watchOS 7.0, *) public class AnimatedImageViewWrapper : PlatformView { - var wrapped = SDAnimatedImageView() + /// The wrapped actual image view, using SDWebImage's aniamted image view + public var wrapped = SDAnimatedImageView() var interpolationQuality = CGInterpolationQuality.default var shouldAntialias = false var resizable = false - override public func draw(_ rect: CGRect) { + public override func draw(_ rect: CGRect) { #if os(macOS) guard let ctx = NSGraphicsContext.current?.cgContext else { return From 71ce58eec4412c17a824a4cad8db4d4814ce3117 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 29 Nov 2023 16:10:17 +0800 Subject: [PATCH 2/5] Little code garden --- SDWebImageSwiftUI/Classes/AnimatedImage.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/SDWebImageSwiftUI/Classes/AnimatedImage.swift b/SDWebImageSwiftUI/Classes/AnimatedImage.swift index 1a6adbf..7e0248f 100644 --- a/SDWebImageSwiftUI/Classes/AnimatedImage.swift +++ b/SDWebImageSwiftUI/Classes/AnimatedImage.swift @@ -178,11 +178,7 @@ public struct AnimatedImage : PlatformViewRepresentable { _imageModel = ObservedObject(wrappedValue: imageModel) } - #if os(macOS) - public typealias NSViewType = AnimatedImageViewWrapper - #else - public typealias UIViewType = AnimatedImageViewWrapper - #endif + public typealias PlatformViewType = AnimatedImageViewWrapper public typealias Coordinator = AnimatedImageCoordinator From e120c3bb61781db5086d9f2e25b3920360bd2901 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 30 Nov 2023 15:18:02 +0800 Subject: [PATCH 3/5] Debug CI for unit test --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 58fa29f..7544522 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -134,7 +134,7 @@ jobs: - name: Test - ${{ matrix.macOSDestination }} run: | set -o pipefail - xcodebuild test -workspace "${{ env.WORKSPACE_NAME }}" -scheme "${{ env.OSXSCHEME }}" -destination "${{ matrix.macOSDestination }}" -configuration Debug CODE_SIGNING_ALLOWED=NO | xcpretty -c + xcodebuild test -workspace "${{ env.WORKSPACE_NAME }}" -scheme "${{ env.OSXSCHEME }}" -destination "${{ matrix.macOSDestination }}" -configuration Debug CODE_SIGNING_ALLOWED=NO mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/macOS - name: Test - ${{ matrix.tvOSDestination }} From 23d1d3b2a0112524988d17abe36d9f3cf8b6c7b3 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 30 Nov 2023 15:54:05 +0800 Subject: [PATCH 4/5] Fix unit test xcode project integration --- .../project.pbxproj | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj b/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj index 5b905c2..2a26b45 100644 --- a/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj +++ b/Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj @@ -41,18 +41,13 @@ 32ABE4F32AA3759900331406 /* SDWebImageWebPCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F22AA3759900331406 /* SDWebImageWebPCoder */; }; 32ABE4F52AA3759900331406 /* SDWebImageSVGCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F42AA3759900331406 /* SDWebImageSVGCoder */; }; 32ABE4F72AA3759900331406 /* SDWebImagePDFCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F62AA3759900331406 /* SDWebImagePDFCoder */; }; - 32ABE4F92AA375A500331406 /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F82AA375A500331406 /* SDWebImage */; }; 32ABE4FD2AA375A500331406 /* SDWebImageWebPCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */; }; 32ABE4FF2AA375A500331406 /* SDWebImageSVGCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4FE2AA375A500331406 /* SDWebImageSVGCoder */; }; 32ABE5012AA375A500331406 /* SDWebImagePDFCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE5002AA375A500331406 /* SDWebImagePDFCoder */; }; 32ABE5032AA375B400331406 /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE5022AA375B400331406 /* SDWebImageSwiftUI */; }; 32B13E812AA368B700BE9B5B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E802AA368B700BE9B5B /* SDWebImageSwiftUI */; }; - 32B13E832AA368B900BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E822AA368B900BE9B5B /* SDWebImage */; }; 32B13E852AA368C600BE9B5B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */; }; - 32B13E872AA368C900BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E862AA368C900BE9B5B /* SDWebImage */; }; - 32B13E892AA368CC00BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E882AA368CC00BE9B5B /* SDWebImage */; }; 32B13E8F2AA368E100BE9B5B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */; }; - 32B13E912AA368E300BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E902AA368E300BE9B5B /* SDWebImage */; }; 32D5D1672A445B260098BDFC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D5D1662A445B260098BDFC /* AppDelegate.swift */; }; 32D5D16B2A445B260098BDFC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32D5D16A2A445B260098BDFC /* Assets.xcassets */; }; 32D5D16E2A445B260098BDFC /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32D5D16D2A445B260098BDFC /* Preview Assets.xcassets */; }; @@ -169,7 +164,6 @@ 322E0E0228D331F00003A55F /* SDWebImageSwiftUITests macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SDWebImageSwiftUITests macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 322E0E0F28D332050003A55F /* SDWebImageSwiftUITests tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SDWebImageSwiftUITests tvOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 326B0D702345C01900D28269 /* DetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailView.swift; sourceTree = ""; }; - 3294617D2AA36759009E391B /* SDWebImage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SDWebImage; path = ../../SDWebImage; sourceTree = ""; }; 3294617E2AA36761009E391B /* SDWebImageSwiftUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SDWebImageSwiftUI; path = ..; sourceTree = ""; }; 32D5D1602A445B250098BDFC /* SDWebImageSwiftUIDemo-visionOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SDWebImageSwiftUIDemo-visionOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 32D5D1662A445B260098BDFC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; wrapsLines = 0; }; @@ -209,7 +203,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 32B13E892AA368CC00BE9B5B /* SDWebImage in Frameworks */, 32D5D1762A445C8F0098BDFC /* SDWebImageSwiftUI in Frameworks */, 32ABE4D92AA3753300331406 /* SDWebImageWebPCoder in Frameworks */, 32ABE4DF2AA3756A00331406 /* SDWebImagePDFCoder in Frameworks */, @@ -245,7 +238,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 32B13E832AA368B900BE9B5B /* SDWebImage in Frameworks */, 32B13E812AA368B700BE9B5B /* SDWebImageSwiftUI in Frameworks */, 32ABE4F32AA3759900331406 /* SDWebImageWebPCoder in Frameworks */, 32ABE4F72AA3759900331406 /* SDWebImagePDFCoder in Frameworks */, @@ -257,7 +249,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 32B13E872AA368C900BE9B5B /* SDWebImage in Frameworks */, 32B13E852AA368C600BE9B5B /* SDWebImageSwiftUI in Frameworks */, 32ABE4E12AA3757B00331406 /* SDWebImageWebPCoder in Frameworks */, 32ABE4E52AA3757B00331406 /* SDWebImagePDFCoder in Frameworks */, @@ -269,7 +260,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 32B13E912AA368E300BE9B5B /* SDWebImage in Frameworks */, 32B13E8F2AA368E100BE9B5B /* SDWebImageSwiftUI in Frameworks */, 32ABE4E72AA3758400331406 /* SDWebImageWebPCoder in Frameworks */, 32ABE4EB2AA3758400331406 /* SDWebImagePDFCoder in Frameworks */, @@ -282,7 +272,6 @@ buildActionMask = 2147483647; files = ( 32ABE5032AA375B400331406 /* SDWebImageSwiftUI in Frameworks */, - 32ABE4F92AA375A500331406 /* SDWebImage in Frameworks */, 32ABE4FD2AA375A500331406 /* SDWebImageWebPCoder in Frameworks */, 32ABE5012AA375A500331406 /* SDWebImagePDFCoder in Frameworks */, 32ABE4FF2AA375A500331406 /* SDWebImageSVGCoder in Frameworks */, @@ -443,7 +432,6 @@ 607FACC71AFB9204008FA782 = { isa = PBXGroup; children = ( - 3294617D2AA36759009E391B /* SDWebImage */, 3294617E2AA36761009E391B /* SDWebImageSwiftUI */, 607FACF51AFB993E008FA782 /* Podspec Metadata */, 320CDC2A22FADB44007CF858 /* SDWebImageSwiftUIDemo */, @@ -503,7 +491,6 @@ name = SDWebImageSwiftUIDemo; packageProductDependencies = ( 32D5D1752A445C8F0098BDFC /* SDWebImageSwiftUI */, - 32B13E882AA368CC00BE9B5B /* SDWebImage */, 32ABE4D82AA3753300331406 /* SDWebImageWebPCoder */, 32ABE4DB2AA3755D00331406 /* SDWebImageSVGCoder */, 32ABE4DE2AA3756A00331406 /* SDWebImagePDFCoder */, @@ -593,7 +580,6 @@ name = "SDWebImageSwiftUIDemo-visionOS"; packageProductDependencies = ( 32B13E802AA368B700BE9B5B /* SDWebImageSwiftUI */, - 32B13E822AA368B900BE9B5B /* SDWebImage */, 32ABE4F22AA3759900331406 /* SDWebImageWebPCoder */, 32ABE4F42AA3759900331406 /* SDWebImageSVGCoder */, 32ABE4F62AA3759900331406 /* SDWebImagePDFCoder */, @@ -617,7 +603,6 @@ name = "SDWebImageSwiftUIDemo-macOS"; packageProductDependencies = ( 32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */, - 32B13E862AA368C900BE9B5B /* SDWebImage */, 32ABE4E02AA3757B00331406 /* SDWebImageWebPCoder */, 32ABE4E22AA3757B00331406 /* SDWebImageSVGCoder */, 32ABE4E42AA3757B00331406 /* SDWebImagePDFCoder */, @@ -641,7 +626,6 @@ name = "SDWebImageSwiftUIDemo-tvOS"; packageProductDependencies = ( 32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */, - 32B13E902AA368E300BE9B5B /* SDWebImage */, 32ABE4E62AA3758400331406 /* SDWebImageWebPCoder */, 32ABE4E82AA3758400331406 /* SDWebImageSVGCoder */, 32ABE4EA2AA3758400331406 /* SDWebImagePDFCoder */, @@ -702,7 +686,6 @@ ); name = "SDWebImageSwiftUIDemo-watchOS WatchKit Extension"; packageProductDependencies = ( - 32ABE4F82AA375A500331406 /* SDWebImage */, 32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */, 32ABE4FE2AA375A500331406 /* SDWebImageSVGCoder */, 32ABE5002AA375A500331406 /* SDWebImagePDFCoder */, @@ -2025,10 +2008,6 @@ package = 32ABE4DD2AA3756A00331406 /* XCRemoteSwiftPackageReference "SDWebImagePDFCoder" */; productName = SDWebImagePDFCoder; }; - 32ABE4F82AA375A500331406 /* SDWebImage */ = { - isa = XCSwiftPackageProductDependency; - productName = SDWebImage; - }; 32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */ = { isa = XCSwiftPackageProductDependency; package = 32ABE4D72AA3753300331406 /* XCRemoteSwiftPackageReference "SDWebImageWebPCoder" */; @@ -2052,30 +2031,14 @@ isa = XCSwiftPackageProductDependency; productName = SDWebImageSwiftUI; }; - 32B13E822AA368B900BE9B5B /* SDWebImage */ = { - isa = XCSwiftPackageProductDependency; - productName = SDWebImage; - }; 32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */ = { isa = XCSwiftPackageProductDependency; productName = SDWebImageSwiftUI; }; - 32B13E862AA368C900BE9B5B /* SDWebImage */ = { - isa = XCSwiftPackageProductDependency; - productName = SDWebImage; - }; - 32B13E882AA368CC00BE9B5B /* SDWebImage */ = { - isa = XCSwiftPackageProductDependency; - productName = SDWebImage; - }; 32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */ = { isa = XCSwiftPackageProductDependency; productName = SDWebImageSwiftUI; }; - 32B13E902AA368E300BE9B5B /* SDWebImage */ = { - isa = XCSwiftPackageProductDependency; - productName = SDWebImage; - }; 32D5D1752A445C8F0098BDFC /* SDWebImageSwiftUI */ = { isa = XCSwiftPackageProductDependency; productName = SDWebImageSwiftUI; From 25ffe1ef812e6c5ab32d56e8332594bf0f75c69a Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 30 Nov 2023 15:36:19 +0800 Subject: [PATCH 5/5] Change the CI test into macOS 13 Workaround the test framework issues --- .github/workflows/CI.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7544522..6cadb84 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,7 +14,7 @@ permissions: jobs: Pods: name: Cocoapods Lint - runs-on: macos-12 + runs-on: macos-13 env: DEVELOPER_DIR: /Applications/Xcode_14.1.app steps: @@ -34,7 +34,7 @@ jobs: Demo: name: Run Demo - runs-on: macos-12 + runs-on: macos-13 env: DEVELOPER_DIR: /Applications/Xcode_14.1.app WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace @@ -44,11 +44,11 @@ jobs: WATCHSCHEME: SDWebImageSwiftUIDemo-watchOS WatchKit App strategy: matrix: - iosDestination: ["name=iPhone 13 Pro"] - tvOSDestination: ["name=Apple TV"] + iosDestination: ["platform=iOS Simulator,name=iPhone 14 Pro"] + tvOSDestination: ["platform=tvOS Simulator,name=Apple TV"] watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 (45mm)"] macOSDestination: ["platform=macOS"] - macCatalystDestination: ["platform=macOS,arch=x86_64,variant=Mac Catalyst"] + macCatalystDestination: ["platform=macOS,variant=Mac Catalyst"] steps: - name: Checkout uses: actions/checkout@v2 @@ -92,7 +92,7 @@ jobs: Test: name: Unit Test - runs-on: macos-12 + runs-on: macos-13 env: DEVELOPER_DIR: /Applications/Xcode_14.1.app WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace @@ -101,9 +101,9 @@ jobs: TVSCHEME: SDWebImageSwiftUITests tvOS strategy: matrix: - iosDestination: ["platform=iOS Simulator,name=iPhone 13 Pro"] - macOSDestination: ["platform=macOS,arch=x86_64"] - tvOSDestination: ["platform=tvOS Simulator,name=Apple TV 4K"] + iosDestination: ["platform=iOS Simulator,name=iPhone 14 Pro"] + macOSDestination: ["platform=macOS"] + tvOSDestination: ["platform=tvOS Simulator,name=Apple TV"] steps: - name: Checkout uses: actions/checkout@v2 @@ -154,7 +154,7 @@ jobs: Build: name: Build Library - runs-on: macos-12 + runs-on: macos-13 env: DEVELOPER_DIR: /Applications/Xcode_14.1.app PROJECT_NAME: SDWebImageSwiftUI.xcodeproj