lorin-vr/justifiableflowlayout
A SwiftUI layout that arranges a collection of items from left to right and top to bottom, in sequential order.
Usage
Sample:
import JustifiableFlowLayout
let uniqueWords = ["cloud", "hill", "thunder", "if", "run", "fright", "just", "twenty", "agent", "theatre", "ink", "so", "rig", "week", "range", "today"]
JustifiableFlowLayout(minSpacing: 10, shouldJustify: false) {
ForEach(uniqueWords, id: \.self) { word in
Text(word)
.padding(10)
.border(Color.mint, width: 2)
}
}
JustifiableFlowLayout also works well inside a ScrollView.
Installation
Swift package manager
Add the swift package to your project:
https://github.com/lorin-vr/JustifiableFlowLayout.gitDiscussion
JustifiableFlowLayout can be used as an alternative to SwiftUI collection view layouts like Grid and LazyVGrid.
Unlike LazyVGrid, JustifiableFlowLayout lays out its items all at once. This potentially allows for more performant layout and animation, but may not be suitable for a large collection of items.
Unlike Grid, you don't specify the number of rows required. JustifiableFlowLayout will decide how many rows it needs based on the item sizes. When using JustifiableFlowLayout, there is no need to define GridItem or GridRow.
Package Metadata
Repository: lorin-vr/justifiableflowlayout
Default branch: main
README: README.md