Skip to content

Commit

Permalink
Merge pull request #285 from SDWebImage/feature/export_animated_image…
Browse files Browse the repository at this point in the history
…_view_type

Update the AnimatedImage API to expose the SDAnimatedImageView
  • Loading branch information
dreampiggy authored Dec 1, 2023
2 parents 6bd9811 + 25ffe1e commit 4012a65
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 61 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
37 changes: 0 additions & 37 deletions Example/SDWebImageSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
3294617D2AA36759009E391B /* SDWebImage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SDWebImage; path = ../../SDWebImage; sourceTree = "<group>"; };
3294617E2AA36761009E391B /* SDWebImageSwiftUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SDWebImageSwiftUI; path = ..; sourceTree = "<group>"; };
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 = "<group>"; wrapsLines = 0; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand Down Expand Up @@ -443,7 +432,6 @@
607FACC71AFB9204008FA782 = {
isa = PBXGroup;
children = (
3294617D2AA36759009E391B /* SDWebImage */,
3294617E2AA36761009E391B /* SDWebImageSwiftUI */,
607FACF51AFB993E008FA782 /* Podspec Metadata */,
320CDC2A22FADB44007CF858 /* SDWebImageSwiftUIDemo */,
Expand Down Expand Up @@ -503,7 +491,6 @@
name = SDWebImageSwiftUIDemo;
packageProductDependencies = (
32D5D1752A445C8F0098BDFC /* SDWebImageSwiftUI */,
32B13E882AA368CC00BE9B5B /* SDWebImage */,
32ABE4D82AA3753300331406 /* SDWebImageWebPCoder */,
32ABE4DB2AA3755D00331406 /* SDWebImageSVGCoder */,
32ABE4DE2AA3756A00331406 /* SDWebImagePDFCoder */,
Expand Down Expand Up @@ -593,7 +580,6 @@
name = "SDWebImageSwiftUIDemo-visionOS";
packageProductDependencies = (
32B13E802AA368B700BE9B5B /* SDWebImageSwiftUI */,
32B13E822AA368B900BE9B5B /* SDWebImage */,
32ABE4F22AA3759900331406 /* SDWebImageWebPCoder */,
32ABE4F42AA3759900331406 /* SDWebImageSVGCoder */,
32ABE4F62AA3759900331406 /* SDWebImagePDFCoder */,
Expand All @@ -617,7 +603,6 @@
name = "SDWebImageSwiftUIDemo-macOS";
packageProductDependencies = (
32B13E842AA368C600BE9B5B /* SDWebImageSwiftUI */,
32B13E862AA368C900BE9B5B /* SDWebImage */,
32ABE4E02AA3757B00331406 /* SDWebImageWebPCoder */,
32ABE4E22AA3757B00331406 /* SDWebImageSVGCoder */,
32ABE4E42AA3757B00331406 /* SDWebImagePDFCoder */,
Expand All @@ -641,7 +626,6 @@
name = "SDWebImageSwiftUIDemo-tvOS";
packageProductDependencies = (
32B13E8E2AA368E100BE9B5B /* SDWebImageSwiftUI */,
32B13E902AA368E300BE9B5B /* SDWebImage */,
32ABE4E62AA3758400331406 /* SDWebImageWebPCoder */,
32ABE4E82AA3758400331406 /* SDWebImageSVGCoder */,
32ABE4EA2AA3758400331406 /* SDWebImagePDFCoder */,
Expand Down Expand Up @@ -702,7 +686,6 @@
);
name = "SDWebImageSwiftUIDemo-watchOS WatchKit Extension";
packageProductDependencies = (
32ABE4F82AA375A500331406 /* SDWebImage */,
32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */,
32ABE4FE2AA375A500331406 /* SDWebImageSVGCoder */,
32ABE5002AA375A500331406 /* SDWebImagePDFCoder */,
Expand Down Expand Up @@ -2025,10 +2008,6 @@
package = 32ABE4DD2AA3756A00331406 /* XCRemoteSwiftPackageReference "SDWebImagePDFCoder" */;
productName = SDWebImagePDFCoder;
};
32ABE4F82AA375A500331406 /* SDWebImage */ = {
isa = XCSwiftPackageProductDependency;
productName = SDWebImage;
};
32ABE4FC2AA375A500331406 /* SDWebImageWebPCoder */ = {
isa = XCSwiftPackageProductDependency;
package = 32ABE4D72AA3753300331406 /* XCRemoteSwiftPackageReference "SDWebImageWebPCoder" */;
Expand All @@ -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;
Expand Down
18 changes: 7 additions & 11 deletions SDWebImageSwiftUI/Classes/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -770,23 +766,23 @@ 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
}

/// 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
}

/// 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
}
}
Expand Down
5 changes: 3 additions & 2 deletions SDWebImageSwiftUI/Classes/ImageViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4012a65

Please sign in to comment.