Skip to content

Improve canSelectAction, selectionAction#85

Merged
raulriera merged 4 commits intoShopify:masterfrom
dcramps:add-deselection-callback
Apr 30, 2018
Merged

Improve canSelectAction, selectionAction#85
raulriera merged 4 commits intoShopify:masterfrom
dcramps:add-deselection-callback

Conversation

@dcramps
Copy link
Copy Markdown
Contributor

@dcramps dcramps commented Apr 28, 2018

Been using this framework in a project for a bit and so far it's been great, but a few things are missing that I would like to fix. Examples of changes are included in the demo app.

canSelectAction:

If this closure exists, allowsMultipleSelection is broken. willSelectRowAt now checks for allowsMultipleSelection and doesn't deselect the currently selected row if it's enabled. CollectionData is also fixed for allowsMultipleSelection, although it does not currently call canSelectAction at all. Not sure if that's intended or an oversight?

selectionAction:

The current behaviour only calls this on didSelect. It's useful to know when the user deselects as well, so the closure now sends a boolean indicating whether the user is selecting or deselecting.

@dcramps dcramps requested a review from raulriera as a code owner April 28, 2018 06:53
Copy link
Copy Markdown
Contributor

@raulriera raulriera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! glad to hear you are enjoying an using the library.

I like the changes and top hatting them seems to work fine. My concern is that this introduces a breaking change for everything using this library at the moment, since SelectionAction is so widely used. Would it be better to introduce a DeselectionAction instead? Having a breaking change and the same callback being called twice feels a bit weird.


collectionView?.backgroundColor = .white
functionalData.collectionView = collectionView
collectionView?.allowsMultipleSelection = false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this here or in the tableview. This is the default value

actions: CellActions(
canSelectAction: { callback in
callback(true)
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the canSelectAction either 🙂 on any

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, leftovers from testing. I'll clean this up

@raulriera
Copy link
Copy Markdown
Contributor

although it does not currently call canSelectAction at all. Not sure if that's intended or an oversight?

That is an oversight 🙂 thanks for catching it

style: CellStyle(backgroundColor: .lightGray),
actions: CellActions(
canSelectAction: { callback in
callback(true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the value of this action is ignored in FunctionalCollectionData, using false will won't prevent selection

@dcramps
Copy link
Copy Markdown
Contributor Author

dcramps commented Apr 28, 2018

Updated to add the DeselectionAction. Shouldn't break existing consumers now 👍

@raulriera
Copy link
Copy Markdown
Contributor

Thank you, although the canSelectAction bug is still present in FunctionalCollectionData. Is this what you mentioned that was an oversight from the library?

@dcramps
Copy link
Copy Markdown
Contributor Author

dcramps commented Apr 28, 2018

Yeah, I figured I would leave that for a separate PR. TableData is doing it in willSelectRowAt, but I think the right place in CollectionData would be shouldSelectItemAt, just haven't looked into it yet. I can add it to this PR if you'd like though

Copy link
Copy Markdown
Contributor

@raulriera raulriera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the changes! 👏

@raulriera
Copy link
Copy Markdown
Contributor

Feel free to merge it 🙂

@dcramps
Copy link
Copy Markdown
Contributor Author

dcramps commented Apr 30, 2018

@raulriera I think you'll have to merge, I don't have access (or something is hiding the merge button on GitHub 🤔)

@raulriera
Copy link
Copy Markdown
Contributor

Oh sorry about that 🙂 i thought it wa available once it’s approved

@raulriera raulriera merged commit a4b3e30 into Shopify:master Apr 30, 2018
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

Successfully merging this pull request may close these issues.

2 participants