Skip to content

Commit 4012a65

Browse files
authored
Merge pull request #285 from SDWebImage/feature/export_animated_image_view_type
Update the AnimatedImage API to expose the SDAnimatedImageView
2 parents 6bd9811 + 25ffe1e commit 4012a65

File tree

4 files changed

+21
-61
lines changed

4 files changed

+21
-61
lines changed

.github/workflows/CI.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414
jobs:
1515
Pods:
1616
name: Cocoapods Lint
17-
runs-on: macos-12
17+
runs-on: macos-13
1818
env:
1919
DEVELOPER_DIR: /Applications/Xcode_14.1.app
2020
steps:
@@ -34,7 +34,7 @@ jobs:
3434
3535
Demo:
3636
name: Run Demo
37-
runs-on: macos-12
37+
runs-on: macos-13
3838
env:
3939
DEVELOPER_DIR: /Applications/Xcode_14.1.app
4040
WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace
@@ -44,11 +44,11 @@ jobs:
4444
WATCHSCHEME: SDWebImageSwiftUIDemo-watchOS WatchKit App
4545
strategy:
4646
matrix:
47-
iosDestination: ["name=iPhone 13 Pro"]
48-
tvOSDestination: ["name=Apple TV"]
47+
iosDestination: ["platform=iOS Simulator,name=iPhone 14 Pro"]
48+
tvOSDestination: ["platform=tvOS Simulator,name=Apple TV"]
4949
watchOSDestination: ["platform=watchOS Simulator,name=Apple Watch Series 7 (45mm)"]
5050
macOSDestination: ["platform=macOS"]
51-
macCatalystDestination: ["platform=macOS,arch=x86_64,variant=Mac Catalyst"]
51+
macCatalystDestination: ["platform=macOS,variant=Mac Catalyst"]
5252
steps:
5353
- name: Checkout
5454
uses: actions/checkout@v2
@@ -92,7 +92,7 @@ jobs:
9292
9393
Test:
9494
name: Unit Test
95-
runs-on: macos-12
95+
runs-on: macos-13
9696
env:
9797
DEVELOPER_DIR: /Applications/Xcode_14.1.app
9898
WORKSPACE_NAME: SDWebImageSwiftUI.xcworkspace
@@ -101,9 +101,9 @@ jobs:
101101
TVSCHEME: SDWebImageSwiftUITests tvOS
102102
strategy:
103103
matrix:
104-
iosDestination: ["platform=iOS Simulator,name=iPhone 13 Pro"]
105-
macOSDestination: ["platform=macOS,arch=x86_64"]
106-
tvOSDestination: ["platform=tvOS Simulator,name=Apple TV 4K"]
104+
iosDestination: ["platform=iOS Simulator,name=iPhone 14 Pro"]
105+
macOSDestination: ["platform=macOS"]
106+
tvOSDestination: ["platform=tvOS Simulator,name=Apple TV"]
107107
steps:
108108
- name: Checkout
109109
uses: actions/checkout@v2
@@ -134,7 +134,7 @@ jobs:
134134
- name: Test - ${{ matrix.macOSDestination }}
135135
run: |
136136
set -o pipefail
137-
xcodebuild test -workspace "${{ env.WORKSPACE_NAME }}" -scheme "${{ env.OSXSCHEME }}" -destination "${{ matrix.macOSDestination }}" -configuration Debug CODE_SIGNING_ALLOWED=NO | xcpretty -c
137+
xcodebuild test -workspace "${{ env.WORKSPACE_NAME }}" -scheme "${{ env.OSXSCHEME }}" -destination "${{ matrix.macOSDestination }}" -configuration Debug CODE_SIGNING_ALLOWED=NO
138138
mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/macOS
139139
140140
- name: Test - ${{ matrix.tvOSDestination }}
@@ -154,7 +154,7 @@ jobs:
154154
155155
Build:
156156
name: Build Library
157-
runs-on: macos-12
157+
runs-on: macos-13
158158
env:
159159
DEVELOPER_DIR: /Applications/Xcode_14.1.app
160160
PROJECT_NAME: SDWebImageSwiftUI.xcodeproj

Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,13 @@
4141
32ABE4F32AA3759900331406 /* SDWebImageWebPCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F22AA3759900331406 /* SDWebImageWebPCoder */; };
4242
32ABE4F52AA3759900331406 /* SDWebImageSVGCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F42AA3759900331406 /* SDWebImageSVGCoder */; };
4343
32ABE4F72AA3759900331406 /* SDWebImagePDFCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F62AA3759900331406 /* SDWebImagePDFCoder */; };
44-
32ABE4F92AA375A500331406 /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4F82AA375A500331406 /* SDWebImage */; };
4544
32ABE4FD2AA375A500331406 /* SDWebImageWebPCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */; };
4645
32ABE4FF2AA375A500331406 /* SDWebImageSVGCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE4FE2AA375A500331406 /* SDWebImageSVGCoder */; };
4746
32ABE5012AA375A500331406 /* SDWebImagePDFCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE5002AA375A500331406 /* SDWebImagePDFCoder */; };
4847
32ABE5032AA375B400331406 /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32ABE5022AA375B400331406 /* SDWebImageSwiftUI */; };
4948
32B13E812AA368B700BE9B5B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E802AA368B700BE9B5B /* SDWebImageSwiftUI */; };
50-
32B13E832AA368B900BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E822AA368B900BE9B5B /* SDWebImage */; };
5149
32B13E852AA368C600BE9B5B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */; };
52-
32B13E872AA368C900BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E862AA368C900BE9B5B /* SDWebImage */; };
53-
32B13E892AA368CC00BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E882AA368CC00BE9B5B /* SDWebImage */; };
5450
32B13E8F2AA368E100BE9B5B /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */; };
55-
32B13E912AA368E300BE9B5B /* SDWebImage in Frameworks */ = {isa = PBXBuildFile; productRef = 32B13E902AA368E300BE9B5B /* SDWebImage */; };
5651
32D5D1672A445B260098BDFC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D5D1662A445B260098BDFC /* AppDelegate.swift */; };
5752
32D5D16B2A445B260098BDFC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32D5D16A2A445B260098BDFC /* Assets.xcassets */; };
5853
32D5D16E2A445B260098BDFC /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32D5D16D2A445B260098BDFC /* Preview Assets.xcassets */; };
@@ -169,7 +164,6 @@
169164
322E0E0228D331F00003A55F /* SDWebImageSwiftUITests macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SDWebImageSwiftUITests macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
170165
322E0E0F28D332050003A55F /* SDWebImageSwiftUITests tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SDWebImageSwiftUITests tvOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
171166
326B0D702345C01900D28269 /* DetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailView.swift; sourceTree = "<group>"; };
172-
3294617D2AA36759009E391B /* SDWebImage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SDWebImage; path = ../../SDWebImage; sourceTree = "<group>"; };
173167
3294617E2AA36761009E391B /* SDWebImageSwiftUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SDWebImageSwiftUI; path = ..; sourceTree = "<group>"; };
174168
32D5D1602A445B250098BDFC /* SDWebImageSwiftUIDemo-visionOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SDWebImageSwiftUIDemo-visionOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
175169
32D5D1662A445B260098BDFC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; wrapsLines = 0; };
@@ -209,7 +203,6 @@
209203
isa = PBXFrameworksBuildPhase;
210204
buildActionMask = 2147483647;
211205
files = (
212-
32B13E892AA368CC00BE9B5B /* SDWebImage in Frameworks */,
213206
32D5D1762A445C8F0098BDFC /* SDWebImageSwiftUI in Frameworks */,
214207
32ABE4D92AA3753300331406 /* SDWebImageWebPCoder in Frameworks */,
215208
32ABE4DF2AA3756A00331406 /* SDWebImagePDFCoder in Frameworks */,
@@ -245,7 +238,6 @@
245238
isa = PBXFrameworksBuildPhase;
246239
buildActionMask = 2147483647;
247240
files = (
248-
32B13E832AA368B900BE9B5B /* SDWebImage in Frameworks */,
249241
32B13E812AA368B700BE9B5B /* SDWebImageSwiftUI in Frameworks */,
250242
32ABE4F32AA3759900331406 /* SDWebImageWebPCoder in Frameworks */,
251243
32ABE4F72AA3759900331406 /* SDWebImagePDFCoder in Frameworks */,
@@ -257,7 +249,6 @@
257249
isa = PBXFrameworksBuildPhase;
258250
buildActionMask = 2147483647;
259251
files = (
260-
32B13E872AA368C900BE9B5B /* SDWebImage in Frameworks */,
261252
32B13E852AA368C600BE9B5B /* SDWebImageSwiftUI in Frameworks */,
262253
32ABE4E12AA3757B00331406 /* SDWebImageWebPCoder in Frameworks */,
263254
32ABE4E52AA3757B00331406 /* SDWebImagePDFCoder in Frameworks */,
@@ -269,7 +260,6 @@
269260
isa = PBXFrameworksBuildPhase;
270261
buildActionMask = 2147483647;
271262
files = (
272-
32B13E912AA368E300BE9B5B /* SDWebImage in Frameworks */,
273263
32B13E8F2AA368E100BE9B5B /* SDWebImageSwiftUI in Frameworks */,
274264
32ABE4E72AA3758400331406 /* SDWebImageWebPCoder in Frameworks */,
275265
32ABE4EB2AA3758400331406 /* SDWebImagePDFCoder in Frameworks */,
@@ -282,7 +272,6 @@
282272
buildActionMask = 2147483647;
283273
files = (
284274
32ABE5032AA375B400331406 /* SDWebImageSwiftUI in Frameworks */,
285-
32ABE4F92AA375A500331406 /* SDWebImage in Frameworks */,
286275
32ABE4FD2AA375A500331406 /* SDWebImageWebPCoder in Frameworks */,
287276
32ABE5012AA375A500331406 /* SDWebImagePDFCoder in Frameworks */,
288277
32ABE4FF2AA375A500331406 /* SDWebImageSVGCoder in Frameworks */,
@@ -443,7 +432,6 @@
443432
607FACC71AFB9204008FA782 = {
444433
isa = PBXGroup;
445434
children = (
446-
3294617D2AA36759009E391B /* SDWebImage */,
447435
3294617E2AA36761009E391B /* SDWebImageSwiftUI */,
448436
607FACF51AFB993E008FA782 /* Podspec Metadata */,
449437
320CDC2A22FADB44007CF858 /* SDWebImageSwiftUIDemo */,
@@ -503,7 +491,6 @@
503491
name = SDWebImageSwiftUIDemo;
504492
packageProductDependencies = (
505493
32D5D1752A445C8F0098BDFC /* SDWebImageSwiftUI */,
506-
32B13E882AA368CC00BE9B5B /* SDWebImage */,
507494
32ABE4D82AA3753300331406 /* SDWebImageWebPCoder */,
508495
32ABE4DB2AA3755D00331406 /* SDWebImageSVGCoder */,
509496
32ABE4DE2AA3756A00331406 /* SDWebImagePDFCoder */,
@@ -593,7 +580,6 @@
593580
name = "SDWebImageSwiftUIDemo-visionOS";
594581
packageProductDependencies = (
595582
32B13E802AA368B700BE9B5B /* SDWebImageSwiftUI */,
596-
32B13E822AA368B900BE9B5B /* SDWebImage */,
597583
32ABE4F22AA3759900331406 /* SDWebImageWebPCoder */,
598584
32ABE4F42AA3759900331406 /* SDWebImageSVGCoder */,
599585
32ABE4F62AA3759900331406 /* SDWebImagePDFCoder */,
@@ -617,7 +603,6 @@
617603
name = "SDWebImageSwiftUIDemo-macOS";
618604
packageProductDependencies = (
619605
32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */,
620-
32B13E862AA368C900BE9B5B /* SDWebImage */,
621606
32ABE4E02AA3757B00331406 /* SDWebImageWebPCoder */,
622607
32ABE4E22AA3757B00331406 /* SDWebImageSVGCoder */,
623608
32ABE4E42AA3757B00331406 /* SDWebImagePDFCoder */,
@@ -641,7 +626,6 @@
641626
name = "SDWebImageSwiftUIDemo-tvOS";
642627
packageProductDependencies = (
643628
32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */,
644-
32B13E902AA368E300BE9B5B /* SDWebImage */,
645629
32ABE4E62AA3758400331406 /* SDWebImageWebPCoder */,
646630
32ABE4E82AA3758400331406 /* SDWebImageSVGCoder */,
647631
32ABE4EA2AA3758400331406 /* SDWebImagePDFCoder */,
@@ -702,7 +686,6 @@
702686
);
703687
name = "SDWebImageSwiftUIDemo-watchOS WatchKit Extension";
704688
packageProductDependencies = (
705-
32ABE4F82AA375A500331406 /* SDWebImage */,
706689
32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */,
707690
32ABE4FE2AA375A500331406 /* SDWebImageSVGCoder */,
708691
32ABE5002AA375A500331406 /* SDWebImagePDFCoder */,
@@ -2025,10 +2008,6 @@
20252008
package = 32ABE4DD2AA3756A00331406 /* XCRemoteSwiftPackageReference "SDWebImagePDFCoder" */;
20262009
productName = SDWebImagePDFCoder;
20272010
};
2028-
32ABE4F82AA375A500331406 /* SDWebImage */ = {
2029-
isa = XCSwiftPackageProductDependency;
2030-
productName = SDWebImage;
2031-
};
20322011
32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */ = {
20332012
isa = XCSwiftPackageProductDependency;
20342013
package = 32ABE4D72AA3753300331406 /* XCRemoteSwiftPackageReference "SDWebImageWebPCoder" */;
@@ -2052,30 +2031,14 @@
20522031
isa = XCSwiftPackageProductDependency;
20532032
productName = SDWebImageSwiftUI;
20542033
};
2055-
32B13E822AA368B900BE9B5B /* SDWebImage */ = {
2056-
isa = XCSwiftPackageProductDependency;
2057-
productName = SDWebImage;
2058-
};
20592034
32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */ = {
20602035
isa = XCSwiftPackageProductDependency;
20612036
productName = SDWebImageSwiftUI;
20622037
};
2063-
32B13E862AA368C900BE9B5B /* SDWebImage */ = {
2064-
isa = XCSwiftPackageProductDependency;
2065-
productName = SDWebImage;
2066-
};
2067-
32B13E882AA368CC00BE9B5B /* SDWebImage */ = {
2068-
isa = XCSwiftPackageProductDependency;
2069-
productName = SDWebImage;
2070-
};
20712038
32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */ = {
20722039
isa = XCSwiftPackageProductDependency;
20732040
productName = SDWebImageSwiftUI;
20742041
};
2075-
32B13E902AA368E300BE9B5B /* SDWebImage */ = {
2076-
isa = XCSwiftPackageProductDependency;
2077-
productName = SDWebImage;
2078-
};
20792042
32D5D1752A445C8F0098BDFC /* SDWebImageSwiftUI */ = {
20802043
isa = XCSwiftPackageProductDependency;
20812044
productName = SDWebImageSwiftUI;

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ final class AnimatedImageHandler: ObservableObject {
6666
@Published var failureBlock: ((Error) -> Void)?
6767
@Published var progressBlock: ((Int, Int) -> Void)?
6868
// Coordinator Handler
69-
@Published var viewCreateBlock: ((PlatformView, AnimatedImage.Context) -> Void)?
70-
@Published var viewUpdateBlock: ((PlatformView, AnimatedImage.Context) -> Void)?
69+
@Published var viewCreateBlock: ((SDAnimatedImageView, AnimatedImage.Context) -> Void)?
70+
@Published var viewUpdateBlock: ((SDAnimatedImageView, AnimatedImage.Context) -> Void)?
7171
}
7272

7373
/// Layout Binding Object, supports dynamic @State changes
@@ -109,7 +109,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
109109
/// A observed object to pass through the image manager loading status to indicator
110110
@ObservedObject var indicatorStatus = IndicatorStatus()
111111

112-
static var viewDestroyBlock: ((PlatformView, Coordinator) -> Void)?
112+
static var viewDestroyBlock: ((SDAnimatedImageView, Coordinator) -> Void)?
113113

114114
/// A Binding to control the animation. You can bind external logic to control the animation status.
115115
/// True to start animation, false to stop animation.
@@ -178,11 +178,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
178178
_imageModel = ObservedObject(wrappedValue: imageModel)
179179
}
180180

181-
#if os(macOS)
182-
public typealias NSViewType = AnimatedImageViewWrapper
183-
#else
184-
public typealias UIViewType = AnimatedImageViewWrapper
185-
#endif
181+
public typealias PlatformViewType = AnimatedImageViewWrapper
186182

187183
public typealias Coordinator = AnimatedImageCoordinator
188184

@@ -770,23 +766,23 @@ extension AnimatedImage {
770766
/// Provide the action when view representable create the native view.
771767
/// - Parameter action: The action to perform. The first arg is the native view. The seconds arg is the context.
772768
/// - Returns: A view that triggers `action` when view representable create the native view.
773-
public func onViewCreate(perform action: ((PlatformView, Context) -> Void)? = nil) -> AnimatedImage {
769+
public func onViewCreate(perform action: ((SDAnimatedImageView, Context) -> Void)? = nil) -> AnimatedImage {
774770
self.imageHandler.viewCreateBlock = action
775771
return self
776772
}
777773

778774
/// Provide the action when view representable update the native view.
779775
/// - Parameter action: The action to perform. The first arg is the native view. The seconds arg is the context.
780776
/// - Returns: A view that triggers `action` when view representable update the native view.
781-
public func onViewUpdate(perform action: ((PlatformView, Context) -> Void)? = nil) -> AnimatedImage {
777+
public func onViewUpdate(perform action: ((SDAnimatedImageView, Context) -> Void)? = nil) -> AnimatedImage {
782778
self.imageHandler.viewUpdateBlock = action
783779
return self
784780
}
785781

786782
/// Provide the action when view representable destroy the native view
787783
/// - Parameter action: The action to perform. The first arg is the native view. The seconds arg is the coordinator (with userInfo).
788784
/// - Returns: A view that triggers `action` when view representable destroy the native view.
789-
public static func onViewDestroy(perform action: ((PlatformView, Coordinator) -> Void)? = nil) {
785+
public static func onViewDestroy(perform action: ((SDAnimatedImageView, Coordinator) -> Void)? = nil) {
790786
self.viewDestroyBlock = action
791787
}
792788
}

SDWebImageSwiftUI/Classes/ImageViewWrapper.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import SDWebImage
1414
/// Use wrapper to solve tne `UIImageView`/`NSImageView` frame size become image size issue (SwiftUI's Bug)
1515
@available(iOS 14.0, OSX 11.0, tvOS 14.0, watchOS 7.0, *)
1616
public class AnimatedImageViewWrapper : PlatformView {
17-
var wrapped = SDAnimatedImageView()
17+
/// The wrapped actual image view, using SDWebImage's aniamted image view
18+
public var wrapped = SDAnimatedImageView()
1819
var interpolationQuality = CGInterpolationQuality.default
1920
var shouldAntialias = false
2021
var resizable = false
2122

22-
override public func draw(_ rect: CGRect) {
23+
public override func draw(_ rect: CGRect) {
2324
#if os(macOS)
2425
guard let ctx = NSGraphicsContext.current?.cgContext else {
2526
return

0 commit comments

Comments
 (0)