Skip to content

Commit 2ad8897

Browse files
committed
Match the behavior when using resizable on AnimatedImage
1 parent 3714545 commit 2ad8897

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ public struct AnimatedImage : PlatformViewRepresentable {
318318
view.wrapped.contentMode = contentMode
319319
#endif
320320

321+
// Resizable
322+
if let _ = imageLayout.resizingMode {
323+
view.resizable = true
324+
}
325+
321326
// Animated Image does not support resizing mode and rendering mode
322327
if let image = view.wrapped.image, !image.sd_isAnimated, !image.conforms(to: SDAnimatedImageProtocol.self) {
323328
var image = image

SDWebImageSwiftUI/Classes/ImageViewWrapper.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class AnimatedImageViewWrapper : PlatformView {
1717
var wrapped = SDAnimatedImageView()
1818
var interpolationQuality = CGInterpolationQuality.default
1919
var shouldAntialias = false
20+
var resizable = false
2021

2122
override public func draw(_ rect: CGRect) {
2223
#if os(macOS)
@@ -49,10 +50,15 @@ public class AnimatedImageViewWrapper : PlatformView {
4950
/// The container will measure its own size with 1:1 firstly, then change image view size, which cause image view sizing smaller than expected
5051
/// Instead, the container should firstly return its own size with image view's aspect ratio
5152
let size = wrapped.intrinsicContentSize
52-
if size.width > 0 && size.height > 0 {
53-
return size
53+
if resizable {
54+
if size.width > 0 && size.height > 0 {
55+
return size
56+
} else {
57+
return super.intrinsicContentSize
58+
}
5459
} else {
55-
return super.intrinsicContentSize
60+
/// Not resizable, always use image size, like SwiftUI.Image
61+
return size
5662
}
5763
}
5864

0 commit comments

Comments
 (0)