Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to make multiple choices? #8

Open
wogus3602 opened this issue Mar 6, 2022 · 6 comments
Open

Is there a way to make multiple choices? #8

wogus3602 opened this issue Mar 6, 2022 · 6 comments

Comments

@wogus3602
Copy link

Currently, only single selection seems to be supported. How about making Selection support Set<Data.Element>?

@Sameesunkaria
Copy link
Owner

Not currently. But, I’m happily accepting PRs 🙂

@wogus3602
Copy link
Author

Currently testing. If it goes well, I'll send a PR!

@RCCoop
Copy link
Contributor

RCCoop commented Feb 3, 2023

@wogus3602 have you made any progress on this? If not, I'd be interested in helping work on it.

I haven't done anything like this, but I think the challenging part for me would be how to allow initializers to use either Binding<Set<Data.Element>> or Binding<Data.Element>, while the OutlineView's internal variable is... what? Binding to a Set with a hard limit to one element if the initializer was the single-selection variety? How did you plan on going about it?

@wogus3602
Copy link
Author

@RCCoop
I worked on multi-select as below.

    @Binding var selection: Set<Item>
        
    init(
        selection: Binding<Item?>,
        children childrenKeyPath: ChildrenKeyPath<Item>? = nil,
        content: @escaping ListItemContentType<Item>
    ) {
        self._selection = .init {
            if let sel = selection.wrappedValue {
                return Set([sel])
            }
            
            return Set()
        } set: { newValue in
            selection.wrappedValue = newValue.first
        }
        
        self.content = content
        self.childrenKeyPath = childrenKeyPath
    }
    
    init(
        selection: Binding<Set<Item>>,
        children childrenKeyPath: ChildrenKeyPath<Item>? = nil,
        content: @escaping ListItemContentType<Item>
    ) {
        self._selection = selection
        self.content = content
        self.childrenKeyPath = childrenKeyPath
    }

@wogus3602
Copy link
Author

@RCCoop The multi-select work is complete, so I'll post a PR soon.

@RCCoop
Copy link
Contributor

RCCoop commented Feb 7, 2023

@wogus3602 Very cool! Thanks for working on that :-)

wogus3602 pushed a commit to wogus3602/OutlineView that referenced this issue Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants