From cc6860c07d372d9cd7156d8f80334a79ba2531e5 Mon Sep 17 00:00:00 2001 From: Hiroshi Kimura Date: Wed, 8 Mar 2023 19:14:01 +0900 Subject: [PATCH] Fix sizing for iOS13.x (#1) --- Sources/SwiftUIHosting/SwiftUIHostingView.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftUIHosting/SwiftUIHostingView.swift b/Sources/SwiftUIHosting/SwiftUIHostingView.swift index c938d3d..a45afd5 100644 --- a/Sources/SwiftUIHosting/SwiftUIHostingView.swift +++ b/Sources/SwiftUIHosting/SwiftUIHostingView.swift @@ -113,7 +113,14 @@ open class SwiftUIHostingView: UIView { /// Returns calculated size using internal hosting controller open override func sizeThatFits(_ size: CGSize) -> CGSize { - hostingController.sizeThatFits(in: size) + var fixedSize = size + if fixedSize.width == .infinity { + fixedSize.width = UIView.layoutFittingCompressedSize.width + } + if fixedSize.height == .infinity { + fixedSize.height = UIView.layoutFittingCompressedSize.height + } + return hostingController.sizeThatFits(in: fixedSize) } open override func didMoveToWindow() {