SpanGrid is an enriched SwiftUI
LazyVGridthat supports a number of extra features.
All items in the data source must conform to
SpanGridSizeInfoProvider. This protocol adds a single parameter to your
data which informs the grid as to how many columns it should fill.
cellwhich is the same width as a column.
rowwhich will cover all columns, no matter how many columns there are.
spanwhich allows you to specify the exact number of columns. If the value provided is larger than the number of columns, then it will fill the row.
If a cell cannot fit in the remaining space of a row, then it will create a new row leaving whitespace on the previous one.
When returning your custom view for each cell, it will arrive with a metadata model. This model will include information
such as the calculated height of the row. This value may also be
nil in scenarios where we have yet to calculate it.
fixedsize where all rows will be the same height that you have provided.
squarewhere the height of each row is the same as the width of a single column. If your row contains a span of >1, it will still only return the width of a single column.
largestwill return the height of the largest cell in the row allowing for all cells to be of equal height.
none(default) will never return a height.
The width of a single column, the number of columns and the space between columns can be calculated in a number of ways.
fixedprovider which allows you to strictly specify the three values above.
dynamic(default) provides an opinionated column structure which adapts to the size of the device and includes some accessibility changes.
customallows you to provide your own implementation. This will provide you with the current width of the grid.
This allows users to navigate through rows/items using an attached keyboard (iPadOS).
Due to an Apple limitation, we currently use WASD keys rather than arrow keys. We hope this'll change in the future.
When instantiating the SpanGrid, you can pass through keyboard navigation options which includes turning on the feature, as well as turning on/off keyboard discoverability and the localized strings shown to users (default English only strings are provided).
I do not pledge to be an expert in SwiftUI, so there may be many issues with the current implementation. I have tested it the best I can and have seen no real issues with performance or functionality. Feel free to raise issues or pull requests with enhancements, bug fixes, ideas, etc.
No Jordan, this project is not called Spandex, no matter how many times you say it.
|Last commit: 1 week ago|