Skip to content

Commit

Permalink
Merge pull request onevcat#1747 from onevcat/version6
Browse files Browse the repository at this point in the history
Pick changes from version 6
  • Loading branch information
onevcat authored Jul 25, 2021
2 parents 75031ab + d951cb7 commit 3aa11f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class TextAttachmentViewController: UIViewController {
KF.url(URL(string: "https://onevcat.com/assets/images/avatar.jpg")!)
.resizing(referenceSize: CGSize(width: 30, height: 30))
.roundCorner(radius: .point(15))
.set(to: textAttachment, attributedView: label)
.set(to: textAttachment, attributedView: self.getLabel())
}

func getLabel() -> UILabel {
return label
}
}

Expand Down
17 changes: 10 additions & 7 deletions Sources/Extensions/NSTextAttachment+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension KingfisherWrapper where Base: NSTextAttachment {
@discardableResult
public func setImage(
with source: Source?,
attributedView: KFCrossPlatformView,
attributedView: @autoclosure @escaping () -> KFCrossPlatformView,
placeholder: KFCrossPlatformImage? = nil,
options: KingfisherOptionsInfo? = nil,
progressBlock: DownloadProgressBlock? = nil,
Expand Down Expand Up @@ -145,24 +145,26 @@ extension KingfisherWrapper where Base: NSTextAttachment {
@discardableResult
public func setImage(
with resource: Resource?,
attributedView: KFCrossPlatformView,
attributedView: @autoclosure @escaping () -> KFCrossPlatformView,
placeholder: KFCrossPlatformImage? = nil,
options: KingfisherOptionsInfo? = nil,
progressBlock: DownloadProgressBlock? = nil,
completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
{
let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
return setImage(
with: resource.map { .network($0) },
attributedView: attributedView,
placeholder: placeholder,
options: options,
parsedOptions: options,
progressBlock: progressBlock,
completionHandler: completionHandler)
completionHandler: completionHandler
)
}

func setImage(
with source: Source?,
attributedView: KFCrossPlatformView,
attributedView: @escaping () -> KFCrossPlatformView,
placeholder: KFCrossPlatformImage? = nil,
parsedOptions: KingfisherParsedOptionsInfo,
progressBlock: DownloadProgressBlock? = nil,
Expand Down Expand Up @@ -222,10 +224,11 @@ extension KingfisherWrapper where Base: NSTextAttachment {
switch result {
case .success(let value):
self.base.image = value.image
let view = attributedView()
#if canImport(UIKit)
attributedView.setNeedsDisplay()
view.setNeedsDisplay()
#else
attributedView.setNeedsDisplay(attributedView.bounds)
view.setNeedsDisplay(view.bounds)
#endif
case .failure:
if let image = options.onFailureImage {
Expand Down
2 changes: 1 addition & 1 deletion Sources/General/KF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension KF.Builder {
/// - Returns: A task represents the image downloading, if initialized.
/// This value is `nil` if the image is being loaded from cache.
@discardableResult
public func set(to attachment: NSTextAttachment, attributedView: KFCrossPlatformView) -> DownloadTask? {
public func set(to attachment: NSTextAttachment, attributedView: @autoclosure @escaping () -> KFCrossPlatformView) -> DownloadTask? {
let placeholderImage = placeholder as? KFCrossPlatformImage ?? nil
return attachment.kf.setImage(
with: source,
Expand Down

0 comments on commit 3aa11f2

Please sign in to comment.