Skip to content

Commit

Permalink
Better support for intrinsic sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
AvdLee committed Jan 7, 2021
1 parent 3589a30 commit 2bec1f9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/SwiftUIKitView/UIViewContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public struct UIViewContainer<Child: UIView>: Identifiable {
public init(_ view: @autoclosure () -> Child, layout: Layout = .intrinsic) {
self.view = view()
self.layout = layout

switch layout {
case .intrinsic:
return
case .fixed(let size):
self.view.widthAnchor.constraint(equalToConstant: size.width).isActive = true
self.view.heightAnchor.constraint(equalToConstant: size.height).isActive = true
case .fixedWidth(let width):
self.view.widthAnchor.constraint(equalToConstant: width).isActive = true
}
}

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

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

Expand Down

0 comments on commit 2bec1f9

Please # to comment.