$ show ciaranrobrien/SwiftUIMasonry
The SwiftUIMasonry library provides two custom layout types for SwiftUI: `VMasonry` and `HMasonry`, which arrange subviews in a vertical or horizontal masonry grid respectively. These layouts support adaptive or fixed column/row counts, configurable spacing, and two placement modes (fill or order) to control how subviews are positioned. Subviews can also span multiple columns or rows using the `masonryColumnSpan` and `masonryRowSpan` view modifiers. The library is structured as a Swift package with a clear separation between public API and internal implementation. The API exposes the layout structures, configuration enums (for column/row counts and placement mode), and view extensions for setting span values. The internal files contain the layout logic, including a caching mechanism to optimize performance by storing layout results for specific size proposals. Key reusable components include the `MasonryColumnCount` and `MasonryRowCount` enums, which provide a type-safe way to specify adaptive or fixed dimensions, and the layout value system (keys and view extensions) that allows subviews to communicate their span requirements to the parent layout. These components demonstrate solid SwiftUI engineering practices and could be extracted for use in other custom layout systems.
The LLM identified 6 files worth highlighting for reuse:
Defines the MasonryColumnCount enum for specifying fixed or adaptive column counts in VMasonry layouts. Supports ExpressibleByIntegerLiteral for easy use with integer literals. Self-contained and depends only on SwiftUI, making it reusable in any layout system requiring similar column count specification.
Defines the MasonryRowCount enum for specifying fixed or adaptive row counts in HMasonry layouts. Mirrors the structure of MasonryColumnCount. Self-contained and reusable.
Defines the MasonryPlacementMode enum with two cases (fill and order) to control subview placement in masonry layouts. Simple, self-contained, and can be extracted for use in other layout systems needing placement strategies.
Defines the MasonryColumnSpanKey struct conforming to LayoutValueKey, providing the default value for column span in VMasonry layouts. Trivial but necessary for the layout value system, and can be reused as a template for custom layout values.
Defines the MasonryRowSpanKey struct conforming to LayoutValueKey, providing the default value for row span in HMasonry layouts. Similar to MasonryColumnSpanKey.
Provides view extensions masonryColumnSpan and masonryRowSpan to set layout values for subview span in masonry layouts. Depend on the corresponding layout value keys, demonstrating the standard pattern for attaching custom layout data to views in SwiftUI.