Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Support fort shouldSelectItem:atIndexPath #115

@GabrieleCocco

Description

@GabrieleCocco

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions