Skip to content

Snaps dragged item to end of collection if dragged past bounds#119

Open
calvin-godfrey wants to merge 1 commit into
Calvin-LL:mainfrom
calvin-godfrey:main
Open

Snaps dragged item to end of collection if dragged past bounds#119
calvin-godfrey wants to merge 1 commit into
Calvin-LL:mainfrom
calvin-godfrey:main

Conversation

@calvin-godfrey

Copy link
Copy Markdown

This is most applicable for grids and corresponds with issue #118.

If the number of items in a grid is not a perfect multiple of the column/row count, then there can be empty slots at the end of a grid. For example, with 8 items and 3 rows, the layout is:

0 1 2
3 4 5
6 7

In this situation, if the user drags 5 straight down, their intent is likely to move it to the end of the grid, but because the center of 5 is never contained with 7, the code to swap them never runs. Alternately, if the margin between items is big enough, it's not that difficult to drag 4 diagonally between 5 and 7 and have the same issue.

Because there's no way to get the full number of items in the collection without introducing a breaking API change, my code uses state.layoutInfo.visibleItemsInfo.maxOf { it.index } instead to get the highest currently rendered item. This is safe because if the current view doesn't include the end of the grid, then there's no empty spots and no behavior change.

This is my first contribution to another open source library, so please let me know if there's anything else you want me to do!

… an empty spot beyond the end. Most applicable with a grid (did not implement for staggered grid for simplicity)
@calvin-godfrey

Copy link
Copy Markdown
Author

Let me know what you think @Calvin-LL

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.

1 participant