|
|
@@ -61,16 +61,17 @@ extension Kingfisher where Base: ImageView {
|
|
|
completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
|
|
|
{
|
|
|
guard let resource = resource else {
|
|
|
- placeholder?.add(to: self.base)
|
|
|
+ self.placeholder = placeholder
|
|
|
setWebURL(nil)
|
|
|
completionHandler?(nil, nil, .none, nil)
|
|
|
return .empty
|
|
|
}
|
|
|
|
|
|
var options = KingfisherManager.shared.defaultOptions + (options ?? KingfisherEmptyOptionsInfo)
|
|
|
+ let noImageOrPlaceholderSet = base.image == nil && self.placeholder == nil
|
|
|
|
|
|
- if !options.keepCurrentImageWhileLoading || base.image == nil {
|
|
|
- placeholder?.add(to: self.base)
|
|
|
+ if !options.keepCurrentImageWhileLoading || noImageOrPlaceholderSet { // Always set placeholder while there is no image/placehoer yet.
|
|
|
+ self.placeholder = placeholder
|
|
|
}
|
|
|
|
|
|
let maybeIndicator = indicator
|
|
|
@@ -110,7 +111,7 @@ extension Kingfisher where Base: ImageView {
|
|
|
guard let transitionItem = options.lastMatchIgnoringAssociatedValue(.transition(.none)),
|
|
|
case .transition(let transition) = transitionItem, ( options.forceTransition || cacheType == .none) else
|
|
|
{
|
|
|
- placeholder?.remove(from: strongBase)
|
|
|
+ self.placeholder = nil
|
|
|
strongBase.image = image
|
|
|
completionHandler?(image, error, cacheType, imageURL)
|
|
|
return
|
|
|
@@ -121,8 +122,7 @@ extension Kingfisher where Base: ImageView {
|
|
|
animations: { maybeIndicator?.stopAnimatingView() },
|
|
|
completion: { _ in
|
|
|
|
|
|
- placeholder?.remove(from: strongBase)
|
|
|
-
|
|
|
+ self.placeholder = nil
|
|
|
UIView.transition(with: strongBase, duration: transition.duration,
|
|
|
options: [transition.animationOptions, .allowUserInteraction],
|
|
|
animations: {
|
|
|
@@ -156,6 +156,7 @@ extension Kingfisher where Base: ImageView {
|
|
|
private var lastURLKey: Void?
|
|
|
private var indicatorKey: Void?
|
|
|
private var indicatorTypeKey: Void?
|
|
|
+private var placeholderKey: Void?
|
|
|
private var imageTaskKey: Void?
|
|
|
|
|
|
extension Kingfisher where Base: ImageView {
|
|
|
@@ -229,6 +230,26 @@ extension Kingfisher where Base: ImageView {
|
|
|
fileprivate func setImageTask(_ task: RetrieveImageTask?) {
|
|
|
objc_setAssociatedObject(base, &imageTaskKey, task, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
|
|
}
|
|
|
+
|
|
|
+ public fileprivate(set) var placeholder: Placeholder? {
|
|
|
+ get {
|
|
|
+ return (objc_getAssociatedObject(base, &placeholderKey) as? Box<Placeholder?>)?.value
|
|
|
+ }
|
|
|
+
|
|
|
+ set {
|
|
|
+ if let previousPlaceholder = placeholder {
|
|
|
+ previousPlaceholder.remove(from: base)
|
|
|
+ }
|
|
|
+
|
|
|
+ if let newPlaceholder = newValue {
|
|
|
+ newPlaceholder.add(to: base)
|
|
|
+ } else {
|
|
|
+ base.image = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ objc_setAssociatedObject(base, &placeholderKey, Box(value: newValue), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|