This work is absolutely great!
It would be nice if you could extend it to support shouldSelectItem:atIndexPath and shouldDeselectItem:atIndexPath, which come in handy in several cases.
For example, it's currently impossible to set a max count of items selectable. Disabling the collection won't work cause it would prevent from deselecting currently selected items.
They could come as optional closures in the constructor as follows:
ASCollectionView {
data: tags,
dataID: \.self,
selectedItems: $selectedTags,
shouldSelect: { (group, index) in
self.selectedTags.count < self.maxSelectionCount
})
{ (element, state) in
Text(element)
}
I tried myself forking the project and extending the flow Coordinator -> Collection -> Closure with shouldSelect/Deselect and it works quite well, except the swift compiler exits during codegen with a trap when declaring a closure with the generic argument SectionID:
var shouldSelect: (SectionID, IndexPath.Element) -> Bool = { (_,_) in true}
while specialising for SectionID == Int is limiting, but it works fine
var shouldSelect: (Int, IndexPath.Element) -> Bool = { (_,_) in true}
This work is absolutely great!
It would be nice if you could extend it to support shouldSelectItem:atIndexPath and shouldDeselectItem:atIndexPath, which come in handy in several cases.
For example, it's currently impossible to set a max count of items selectable. Disabling the collection won't work cause it would prevent from deselecting currently selected items.
They could come as optional closures in the constructor as follows:
I tried myself forking the project and extending the flow Coordinator -> Collection -> Closure with shouldSelect/Deselect and it works quite well, except the swift compiler exits during codegen with a trap when declaring a closure with the generic argument SectionID:
var shouldSelect: (SectionID, IndexPath.Element) -> Bool = { (_,_) in true}while specialising for SectionID == Int is limiting, but it works fine
var shouldSelect: (Int, IndexPath.Element) -> Bool = { (_,_) in true}