Skip to content

Commit

Permalink
Merge pull request #2244 from onevcat/MxIris-Library-Forks-master
Browse files Browse the repository at this point in the history
Add KingfisherHasImageComponent to provide a unified way for extensions
  • Loading branch information
onevcat authored Jun 2, 2024
2 parents 6c3f663 + 9666885 commit ba97d52
Show file tree
Hide file tree
Showing 11 changed files with 619 additions and 806 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ jobs:
'watchOS Simulator,name=Apple Watch Series 8 (41mm)'
]
xcode: [
'15.2',
'15.3'
'15.3',
'15.4'
]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
self-hosted: true
- name: Install Gems
run: bundle install
- name: Run tests
env:
DESTINATION: platform=${{ matrix.destination }}
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.3.1
12 changes: 4 additions & 8 deletions Kingfisher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
4BD821622189FC0C0084CC21 /* SessionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD821612189FC0C0084CC21 /* SessionDelegate.swift */; };
4BD821672189FD330084CC21 /* SessionDataTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD821662189FD330084CC21 /* SessionDataTask.swift */; };
4BE688F722FD513100B11168 /* NSButton+Kingfisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D12AB6AD215D2BB50013BA68 /* NSButton+Kingfisher.swift */; };
4BE688F822FD513700B11168 /* WKInterfaceImage+Kingfisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D12AB6AF215D2BB50013BA68 /* WKInterfaceImage+Kingfisher.swift */; };
76FB4FD2262D773E006D15F8 /* GraphicsContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FB4FD1262D773E006D15F8 /* GraphicsContext.swift */; };
C9286407228584EB00257182 /* ImageProgressive.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9286406228584EB00257182 /* ImageProgressive.swift */; };
D1132C9725919F69003E528D /* KFOptionsSetter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1132C9625919F69003E528D /* KFOptionsSetter.swift */; };
Expand Down Expand Up @@ -119,7 +118,7 @@
D1F1F6FF24625EC600910725 /* RetryStrategyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1F1F6FE24625EC600910725 /* RetryStrategyTests.swift */; };
D8FCF6A821C5A0E500F9ABC0 /* RedirectHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8FCF6A721C5A0E500F9ABC0 /* RedirectHandler.swift */; };
D9638BA61C7DC71F0046523D /* ImagePrefetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9638BA41C7DC71F0046523D /* ImagePrefetcherTests.swift */; };
DCEB2842257E4BE100D7A610 /* TVMonogramView+Kingfisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCEB2841257E4BE100D7A610 /* TVMonogramView+Kingfisher.swift */; };
E9E3ED8B2B1F66B200734CFF /* HasImageComponent+Kingfisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E3ED8A2B1F66B200734CFF /* HasImageComponent+Kingfisher.swift */; };
F72CE9CE1FCF17ED00CC522A /* ImageModifierTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72CE9CD1FCF17ED00CC522A /* ImageModifierTests.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -190,7 +189,6 @@
D12AB6AC215D2BB50013BA68 /* ImageView+Kingfisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ImageView+Kingfisher.swift"; sourceTree = "<group>"; };
D12AB6AD215D2BB50013BA68 /* NSButton+Kingfisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSButton+Kingfisher.swift"; sourceTree = "<group>"; };
D12AB6AE215D2BB50013BA68 /* UIButton+Kingfisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Kingfisher.swift"; sourceTree = "<group>"; };
D12AB6AF215D2BB50013BA68 /* WKInterfaceImage+Kingfisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WKInterfaceImage+Kingfisher.swift"; sourceTree = "<group>"; };
D12AB6B1215D2BB50013BA68 /* Kingfisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Kingfisher.swift; sourceTree = "<group>"; };
D12AB6B2215D2BB50013BA68 /* KingfisherError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KingfisherError.swift; sourceTree = "<group>"; };
D12AB6B3215D2BB50013BA68 /* KingfisherManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KingfisherManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -297,7 +295,7 @@
D1F7607623097532000C5269 /* KFImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KFImage.swift; sourceTree = "<group>"; };
D8FCF6A721C5A0E500F9ABC0 /* RedirectHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedirectHandler.swift; sourceTree = "<group>"; };
D9638BA41C7DC71F0046523D /* ImagePrefetcherTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagePrefetcherTests.swift; sourceTree = "<group>"; };
DCEB2841257E4BE100D7A610 /* TVMonogramView+Kingfisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TVMonogramView+Kingfisher.swift"; sourceTree = "<group>"; };
E9E3ED8A2B1F66B200734CFF /* HasImageComponent+Kingfisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HasImageComponent+Kingfisher.swift"; sourceTree = "<group>"; };
F72CE9CD1FCF17ED00CC522A /* ImageModifierTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageModifierTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -396,9 +394,8 @@
D12EB83B24DD8EFC00329EE1 /* NSTextAttachment+Kingfisher.swift */,
D12AB6AC215D2BB50013BA68 /* ImageView+Kingfisher.swift */,
D12AB6AD215D2BB50013BA68 /* NSButton+Kingfisher.swift */,
E9E3ED8A2B1F66B200734CFF /* HasImageComponent+Kingfisher.swift */,
D12AB6AE215D2BB50013BA68 /* UIButton+Kingfisher.swift */,
D12AB6AF215D2BB50013BA68 /* WKInterfaceImage+Kingfisher.swift */,
DCEB2841257E4BE100D7A610 /* TVMonogramView+Kingfisher.swift */,
22FDCE0D2700078B0044D11E /* CPListItem+Kingfisher.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -832,6 +829,7 @@
D12AB6D4215D2BB50013BA68 /* Image.swift in Sources */,
D1AEB09425890DE7008556DF /* ImageBinder.swift in Sources */,
4B8E2917216F3F7F0095FAD1 /* ImageDownloaderDelegate.swift in Sources */,
E9E3ED8B2B1F66B200734CFF /* HasImageComponent+Kingfisher.swift in Sources */,
D1132C9725919F69003E528D /* KFOptionsSetter.swift in Sources */,
D18B3222251852E100662F63 /* KF.swift in Sources */,
D12AB704215D2BB50013BA68 /* Kingfisher.swift in Sources */,
Expand Down Expand Up @@ -869,12 +867,10 @@
D1A37BDE215D34E8009B39B7 /* ImageDrawing.swift in Sources */,
4BD821672189FD330084CC21 /* SessionDataTask.swift in Sources */,
D12AB708215D2BB50013BA68 /* KingfisherError.swift in Sources */,
4BE688F822FD513700B11168 /* WKInterfaceImage+Kingfisher.swift in Sources */,
D12AB724215D2BB50013BA68 /* Box.swift in Sources */,
4B8E291C216F40AA0095FAD1 /* AuthenticationChallengeResponsable.swift in Sources */,
3ADE9AF92A73CD69009A86CA /* String+SHA256.swift in Sources */,
D12AB710215D2BB50013BA68 /* KingfisherOptionsInfo.swift in Sources */,
DCEB2842257E4BE100D7A610 /* TVMonogramView+Kingfisher.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
140 changes: 28 additions & 112 deletions Sources/Extensions/CPListItem+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,123 +110,39 @@ extension KingfisherWrapper where Base: CPListItem {
completionHandler: (@MainActor @Sendable (Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
{
var mutatingSelf = self
guard let source = source else {
/**
* In iOS SDK 14.0-14.4 the image param was non-`nil`. The SDK changed in 14.5
* to allow `nil`. The compiler version 5.4 was introduced in this same SDK,
* which allows >=14.5 SDK to set a `nil` image. This compile check allows
* newer SDK users to set the image to `nil`, while still allowing older SDK
* users to compile the framework.
*/
#if compiler(>=5.4)
self.base.setImage(placeholder)
#else
if let placeholder = placeholder {
self.base.setImage(placeholder)
}
#endif

mutatingSelf.taskIdentifier = nil
completionHandler?(.failure(KingfisherError.imageSettingError(reason: .emptySource)))
return nil
}

var options = parsedOptions
if !options.keepCurrentImageWhileLoading {
/**
* In iOS SDK 14.0-14.4 the image param was non-`nil`. The SDK changed in 14.5
* to allow `nil`. The compiler version 5.4 was introduced in this same SDK,
* which allows >=14.5 SDK to set a `nil` image. This compile check allows
* newer SDK users to set the image to `nil`, while still allowing older SDK
* users to compile the framework.
*/
#if compiler(>=5.4)
self.base.setImage(placeholder)
#else // Let older SDK users deal with the older behavior.
if let placeholder = placeholder {
self.base.setImage(placeholder)
}
#endif
}

let issuedIdentifier = Source.Identifier.next()
mutatingSelf.taskIdentifier = issuedIdentifier

if let block = progressBlock {
options.onDataReceived = (options.onDataReceived ?? []) + [ImageLoadingProgressSideEffect(block)]
}

let task = KingfisherManager.shared.retrieveImage(
return setImage(
with: source,
options: options,
downloadTaskUpdated: { task in
Task { @MainActor in mutatingSelf.imageTask = task }
},
progressiveImageSetter: { image in
/**
* In iOS SDK 14.0-14.4 the image param was non-`nil`. The SDK changed in 14.5
* to allow `nil`. The compiler version 5.4 was introduced in this same SDK,
* which allows >=14.5 SDK to set a `nil` image. This compile check allows
* newer SDK users to set the image to `nil`, while still allowing older SDK
* users to compile the framework.
*/
#if compiler(>=5.4)
self.base.setImage(image)
#else // Let older SDK users deal with the older behavior.
if let image = image {
imageAccessor: ImagePropertyAccessor(
setImage: { image, _ in
/**
* In iOS SDK 14.0-14.4 the image param was non-`nil`. The SDK changed in 14.5
* to allow `nil`. The compiler version 5.4 was introduced in this same SDK,
* which allows >=14.5 SDK to set a `nil` image. This compile check allows
* newer SDK users to set the image to `nil`, while still allowing older SDK
* users to compile the framework.
*/
#if compiler(>=5.4)
self.base.setImage(image)
}
#endif
},
referenceTaskIdentifierChecker: { issuedIdentifier == self.taskIdentifier },
completionHandler: { result in
CallbackQueueMain.currentOrAsync {
guard issuedIdentifier == self.taskIdentifier else {
let reason: KingfisherError.ImageSettingErrorReason
do {
let value = try result.get()
reason = .notCurrentSourceTask(result: value, error: nil, source: source)
} catch {
reason = .notCurrentSourceTask(result: nil, error: error, source: source)
}
let error = KingfisherError.imageSettingError(reason: reason)
completionHandler?(.failure(error))
return
}

mutatingSelf.imageTask = nil
mutatingSelf.taskIdentifier = nil

switch result {
case .success(let value):
self.base.setImage(value.image)
completionHandler?(result)

case .failure:
if let image = options.onFailureImage {
/**
* In iOS SDK 14.0-14.4 the image param was non-`nil`. The SDK changed in 14.5
* to allow `nil`. The compiler version 5.4 was introduced in this same SDK,
* which allows >=14.5 SDK to set a `nil` image. This compile check allows
* newer SDK users to set the image to `nil`, while still allowing older SDK
* users to compile the framework.
*/
#if compiler(>=5.4)
self.base.setImage(image)
#else // Let older SDK users deal with the older behavior.
if let unwrapped = image {
self.base.setImage(unwrapped)
}
#endif
}
completionHandler?(result)
#else
if let image = image {
self.base.setImage(image)
}
#endif
},
getImage: {
self.base.image
}
}
),
taskAccessor: TaskPropertyAccessor(
setTaskIdentifier: { mutatingSelf.taskIdentifier = $0 },
getTaskIdentifier: { mutatingSelf.taskIdentifier },
setTask: { mutatingSelf.imageTask = $0 }
),
placeholder: placeholder,
parsedOptions: parsedOptions,
progressBlock: progressBlock,
completionHandler: completionHandler
)

mutatingSelf.imageTask = task
return task
}

// MARK: Cancelling Image
Expand Down
Loading

0 comments on commit ba97d52

Please sign in to comment.