Skip to content

Commit b6039ce

Browse files
constantine-frymeta-codesync[bot]
authored andcommitted
Add constrainedSize modifier
Summary: Adds a new constrainedSize(maxWidth:maxHeight:) modifier to QuickLayout that clamps the parent's proposed size before measuring the child. Unlike .frame(maxWidth:maxHeight:) (FlexibleFrame), this modifier does not create an invisible frame around the child or reposition it with alignment. It simply constrains the proposed size passed to the child and reports the child's actual size as its own. This makes it useful when you want to limit how much space a child is offered without introducing extra layout space around it. The new ConstrainedSizeElement is modeled after FixedFrameElement but differs in three key ways: Reports the child's actual size rather than the frame's size Delegates flexibility to the child instead of reporting .fixedSize Does not perform alignment positioning — the child is placed at the origin Reviewed By: xavierjurado Differential Revision: D94706249 fbshipit-source-id: 26f6a505c64a65964478d2c915962b9bc37c1b6c
1 parent e7caec9 commit b6039ce

6 files changed

Lines changed: 561 additions & 0 deletions

File tree

Sources/QuickLayout/QuickLayoutBridge/QuickLayout.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ public extension Element {
195195
FixedSizeElement(child: self, horizontal: axis.contains(.horizontal), vertical: axis.contains(.vertical))
196196
}
197197

198+
/// Clamps the parent's proposed size to the specified constraints and
199+
/// acquires the child's actual size as its own.
200+
/// Similar to Flexible Frame with maxWidth and maxHeight, but does not
201+
/// leave an invisible space around the child view.
202+
func constrainedSize(maxWidth: CGFloat? = nil, maxHeight: CGFloat? = nil) -> Element & Layout {
203+
ConstrainedSizeElement(child: self, maxWidth: maxWidth, maxHeight: maxHeight)
204+
}
205+
198206
/// Sets the priority by which a parent V/HStack should allocate space to this child.
199207
/// A view's default priority is 0, which distributes available space evenly to all sibling views.
200208
/// Set a higher priority to measure the view first with a larger portion of available space.

0 commit comments

Comments
 (0)