Anyone know if it is possible to select items in the new GridView ? Is there a List(selection:) equivalent API?
SwiftUI CollectionView selection
As far as I checked the documentation, Grids does not have a feature supporting selection.
LazyHGrid
LazyVGrid
You may need to manage selections by yourself.
LazyHGrid
LazyVGrid
You may need to manage selections by yourself.
Add an @State variable to hold selection state
Add a tap gesture action (or a Button) for each item and update selection state
Change appearance of items based on the selection state
...
That is what I exactly did. I conditionally change the data of LazyVGrid and when the grid cells are re-layout, I have an additional check box that is unhidden and enabled in editing mode. But I still don't have the reorder ability though.
The other approach I also tried was to conditionally change the LazyVGrid section into a List/ForEach in editing mode. this way I can at least try to get the reordering functionality too. Reminders app does this but is more refined. I have some animation artifacts and still trying to figure out to fix those in both approaches.
The other approach I also tried was to conditionally change the LazyVGrid section into a List/ForEach in editing mode. this way I can at least try to get the reordering functionality too. Reminders app does this but is more refined. I have some animation artifacts and still trying to figure out to fix those in both approaches.