woxblom / DragListView

Drag and drop to reorder items in a list, grid or board for Android. Based on RecyclerView. Also supports swiping items in a list.
Apache License 2.0
693 stars 177 forks source link

Return the item to its place if the user dragged it to another column. #201

Closed osmovia closed 2 years ago

osmovia commented 2 years ago

Hello. Thanks for the library, very nice project. This is exactly what I was looking for.

Please let me know how I can achieve the following case: The user should not drag and drop items into the specific column. Let 's assume we have 3 columns and we can drag items from 1st column to the rest columns. But we shouldn't able to drag from 2nd and 3rd to 1st. I managed to implement this logic, however, when I drag item from 3rd to 1st, the item is moved to the 2nd column instead of its initial place.

I've attached a video for better understanding.

https://user-images.githubusercontent.com/78955249/177590620-6346672f-a75b-4394-983e-de0ec8c3e718.mov

Thanks in advance!

woxblom commented 2 years ago

Hey, the issue happens because you are allowing an item to be moved from column 3 to column 2. As you can see in the video when you move an item from column 3 and then over to column 1 it moves into (you see the empty space is moved) place in column 2 before moving it to column 1.

So you need to implement so you can only move stuff from column 1. Never from any other column. Or should you be able to move an item from column 3 to column 2 by the way?

osmovia commented 2 years ago

Hi @woxblom,

Thx for prompt answer. Yes, you are able to move item from 2nd to 3rd and vice versa. But once you've moved item from 1st column, you shouldn't be able to move it back (to 1st), only between 2nd and 3rd columns.

woxblom commented 2 years ago

Yeah if that is the case then it will be pretty hard to fix the issue you are describing as the lib will move the item to the last valid position it was in. And when you drag from column 3 over column 2 to column 1 it will see column 2 as a valid position.

woxblom commented 2 years ago

You would need to do some own logic to fix this. You could track where the item is outside the lib with the callbacks for example and if the item is released above an invalid column you could move it manually back to the first position which you then need to keep track of outside the lib.

osmovia commented 2 years ago

Thanks for the help.

https://user-images.githubusercontent.com/78955249/177614659-e150b1a0-1020-4259-8d78-8b38d4e32419.mov