From fbe7dacb66cdcdffb2765881213209bab6af0a7c Mon Sep 17 00:00:00 2001 From: Kazumasa Shimomura Date: Mon, 1 Apr 2024 18:28:23 +0900 Subject: [PATCH] fix: use systemLayoutSizeFitting for SwiftUI sizing --- Sources/SwiftUISupport/ComponentSwiftUISupport.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftUISupport/ComponentSwiftUISupport.swift b/Sources/SwiftUISupport/ComponentSwiftUISupport.swift index 38e16f2..da2fcd3 100644 --- a/Sources/SwiftUISupport/ComponentSwiftUISupport.swift +++ b/Sources/SwiftUISupport/ComponentSwiftUISupport.swift @@ -51,7 +51,16 @@ private struct ComponentRepresenting: UIViewRepresentable { if let height = proposal.height { uiView.bounds.size.height = height } - return uiView.intrinsicContentSize + + if uiView.intrinsicContentSize != CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric) { + return uiView.intrinsicContentSize + } + + return uiView.systemLayoutSizeFitting( + proposal.replacingUnspecifiedDimensions(by: UIView.layoutFittingCompressedSize), + withHorizontalFittingPriority: .required, + verticalFittingPriority: .fittingSizeLevel + ) } }