Skip to content

Commit 2bec1f9

Browse files
committed
Better support for intrinsic sizes
1 parent 3589a30 commit 2bec1f9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/SwiftUIKitView/UIViewContainer.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ public struct UIViewContainer<Child: UIView>: Identifiable {
6363
public init(_ view: @autoclosure () -> Child, layout: Layout = .intrinsic) {
6464
self.view = view()
6565
self.layout = layout
66+
67+
switch layout {
68+
case .intrinsic:
69+
return
70+
case .fixed(let size):
71+
self.view.widthAnchor.constraint(equalToConstant: size.width).isActive = true
72+
self.view.heightAnchor.constraint(equalToConstant: size.height).isActive = true
73+
case .fixedWidth(let width):
74+
self.view.widthAnchor.constraint(equalToConstant: width).isActive = true
75+
}
6676
}
6777

6878
/// Applies the correct size to the SwiftUI `View` container.
@@ -87,8 +97,6 @@ public struct UIViewContainer<Child: UIView>: Identifiable {
8797
extension UIViewContainer: UIViewRepresentable {
8898

8999
public func makeUIView(context: Context) -> UIView {
90-
view.widthAnchor.constraint(equalToConstant: size.width).isActive = true
91-
view.heightAnchor.constraint(equalToConstant: size.height).isActive = true
92100
return view
93101
}
94102

0 commit comments

Comments
 (0)