Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KingfisherHasImageComponent to provide a unified way for extensions #2244

Merged
merged 28 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cf2618d
Add extension to has image property components
Mx-Iris Dec 5, 2023
9cf6e07
Add some extensions
Mx-Iris Dec 5, 2023
fa98a1f
Add some extensions
Mx-Iris Dec 5, 2023
2113a62
Adaptation to multiple platforms
Mx-Iris Dec 5, 2023
5bdefe6
Merge branch 'onevcat:master' into master
Mx-Iris Dec 16, 2023
9dd5bd8
Merge branch 'onevcat:master' into master
Mx-Iris Dec 30, 2023
8ec8143
Merge branch 'onevcat:master' into master
Mx-Iris Jan 14, 2024
dcd5693
Create or update Upstream Sync workflow file.
Mx-Iris Feb 17, 2024
86baa01
Conflict resolution
Mx-Iris Apr 30, 2024
38900fd
Add UIKit Components extensions
Mx-Iris Apr 30, 2024
ca93992
Fixes compatibility issues with other platforms
Mx-Iris Apr 30, 2024
a2fdda2
Merge branch 'master' of https://github.com/MxIris-Library-Forks/King…
onevcat May 3, 2024
6458930
Reset storyboard
onevcat May 3, 2024
2f1cce3
Sync changes in v8 to HasImageComponent
onevcat May 3, 2024
362b543
Remove placeholder and indicator things from KingfisherHasImageComponent
onevcat May 4, 2024
5d2bea8
Adjust format and minor refactor
onevcat May 4, 2024
4298e26
Add watchOS support in KingfisherHasImageComponent
onevcat May 4, 2024
26a3005
Remove watchOS specified interface
onevcat May 4, 2024
98b17d7
Fix a potential stub issue
onevcat May 4, 2024
ad5d1b7
Move TVMonogramView support to extension
onevcat May 5, 2024
054767f
Refactor to split setter caller and actual setting
onevcat May 8, 2024
ebe4743
Extract image task and identifier to setter
onevcat May 14, 2024
cda2849
Simplify the NSButton set image with generic method
onevcat Jun 2, 2024
d77a40a
Update xcode versions
onevcat Jun 2, 2024
94a2828
Do not use ruby setup
onevcat Jun 2, 2024
7ecfe0a
Update ruby version
onevcat Jun 2, 2024
3479f01
Simplify identifier setting and adopt for button types
onevcat Jun 2, 2024
9666885
Use new set image for CPListItem
onevcat Jun 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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