Skip to content

Using the intrinsicContentSize on wrapper container, try to fix the aspect ratio sizing issue #36

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

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions SDWebImageSwiftUI/Classes/ImageViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public class AnimatedImageViewWrapper : PlatformView {
}
#endif

public override var intrinsicContentSize: CGSize {
/// Used to fix SwiftUI layout issue when image view is aspectFit/aspectFill :)
/// The container will measure its own size with 1:1 firstly, then change image view size, which cause image view sizing smaller than expected
/// Instead, the container should firstly return its own size with image view's aspect ratio
let size = wrapped.intrinsicContentSize
if size.width > 0 && size.height > 0 {
let aspectRatio = size.height / size.width
return CGSize(width: 1, height: 1 * aspectRatio)
} else {
return super.intrinsicContentSize
}
}

public override init(frame frameRect: CGRect) {
super.init(frame: frameRect)
addSubview(wrapped)
Expand Down