Skip to content

Commit 3714545

Browse files
committed
Fix the behavior when user does not call any .frame limit, the AnimatedImage with URL should use the image pixel size as view size, not current default tableView cell size
1 parent 9faad75 commit 3714545

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ public struct AnimatedImage : PlatformViewRepresentable {
196196
view.wrapped.sd_setImage(with: imageModel.url, placeholderImage: imageConfiguration.placeholder, options: imageModel.webOptions, context: imageModel.webContext, progress: { (receivedSize, expectedSize, _) in
197197
self.imageHandler.progressBlock?(receivedSize, expectedSize)
198198
}) { (image, error, cacheType, _) in
199-
self.layoutView(view, context: context)
199+
// This is a hack because of Xcode 11.3 bug, the @Published does not trigger another `updateUIView` call
200+
// Here I have to use UIKit API to triger the same effect (the window change implicitly cause re-render)
201+
if let hostingView = AnimatedImage.findHostingView(from: view) {
202+
hostingView.didMoveToWindow()
203+
}
200204
if let image = image {
201205
self.imageHandler.successBlock?(image, cacheType)
202206
} else {
@@ -449,6 +453,17 @@ public struct AnimatedImage : PlatformViewRepresentable {
449453
view.wrapped.playbackRate = 1.0
450454
}
451455
}
456+
457+
private static func findHostingView(from entry: PlatformView) -> PlatformView? {
458+
var superview = entry.superview
459+
while let s = superview {
460+
if NSStringFromClass(type(of: s)).contains("HostingView") {
461+
return s
462+
}
463+
superview = s.superview
464+
}
465+
return nil
466+
}
452467
}
453468

454469
// Layout

SDWebImageSwiftUI/Classes/ImageViewWrapper.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public class AnimatedImageViewWrapper : PlatformView {
5050
/// Instead, the container should firstly return its own size with image view's aspect ratio
5151
let size = wrapped.intrinsicContentSize
5252
if size.width > 0 && size.height > 0 {
53-
let aspectRatio = size.height / size.width
54-
return CGSize(width: 1, height: 1 * aspectRatio)
53+
return size
5554
} else {
5655
return super.intrinsicContentSize
5756
}

0 commit comments

Comments
 (0)