Declaration
compose().geometryGroup()@export(implementation) nonisolated func geometryGroup() -> some ViewDiscussion
By default SwiftUI views push position and size changes down through the view hierarchy, so that only views that draw something (known as leaf views) apply the current animation to their frame rectangle. However in some cases this coalescing behavior can give undesirable results; inserting a geometry group can correct that. A group acts as a barrier between the parent view and its subviews, forcing the position and size values to be resolved and animated by the parent, before being passed down to each subview.
The example below shows one use of this function: ensuring that
the member views of each row in the stack apply (and animate
as) a single geometric transform from their ancestor view,
rather than letting the effects of the ancestor views be
applied separately to each leaf view. If the members of
ItemView may be added and removed at different times the
group ensures that they stay locked together as animations are
applied.
VStack {
ForEach(items) { item in
ItemView(item: item)
.geometryGroup()
}
}Returns: a new view whose geometry is isolated from that of its parent view.
See also
More in Layout.
- alignmentGuideSets the view's vertical alignment.
- aspectRatioConstrains this view's dimensions to the specified aspect ratio.
- containerCornerOffsetAdjusts the view's layout to avoid the container view's corner insets for the specified edges.
- containerRelativeFramePositions this view within an invisible frame with a size relative to the nearest container.
- controlSizeSets the size for controls within this view.
- defaultScrollAnchorAssociates an anchor to control which part of the scroll view's content should be rendered by default.
- dynamicTypeSizeSets the Dynamic Type size within the view to the given value.
- fixedSizeFixes this view at its ideal size.
- flipsForRightToLeftLayoutDirectionSets whether this view mirrors its contents horizontally when the layout direction is right-to-left.
- framePositions this view within an invisible frame.
- gridCellAnchorSpecifies a custom alignment anchor for a view that acts as a grid cell.
- gridCellColumnsTells a view that acts as a cell in a grid to span the specified number of columns.