Snaps dragged item to end of collection if dragged past bounds#119
Open
calvin-godfrey wants to merge 1 commit into
Open
Snaps dragged item to end of collection if dragged past bounds#119calvin-godfrey wants to merge 1 commit into
calvin-godfrey wants to merge 1 commit into
Conversation
… an empty spot beyond the end. Most applicable with a grid (did not implement for staggered grid for simplicity)
Author
|
Let me know what you think @Calvin-LL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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!