GridLayout with Sections: GetSectionIndex return wrong value when dragging upwards
See original GitHub issueUsing a Gridlayout with sections that seperate your items (best represented by the “headers and sections example”):
While you drag, and get the value of getSectionIndex(draggedItemPosition)
in shouldMove(from,to)
->getSectionIndex
will return the wrong index if dragged from screenBottom direction to screenTop direction
Let’s say you have the following situation, 1 item, 1 header/section: [ item1 ] <- “area1” ------Header----- [ item2 ] <- “area2”
Correct behavior from screenTop direction to screenBottom (down):
- You drag item1 to area2
- in the called method
shouldMove
you call and printgetSectionIndex(toPosition)
- You will get 0 (which is fine)
— Starting again with the normal situation shown above — Wrong behavior from screenBottom direction to screenTop direction (up):
- You drag item2 to area1
- in the called method
shouldMove
you call and printgetSectionIndex(toPosition)
- You will get 1 —> which is not correct since the target position does not have any headers before it anymore
If you check after dragging getSectionIndex(item1Position)
again -> you see that it’s correct (it’s 0)
So while dragging the index is not calculated correctly (it does not consider the header that just moved above the dragged item)
As with the last bug, I am using your library extensively, so I am quite happy over quick feedback or even a fix. Thanks in advance
I need this to work correctly in order to prohibit the dragging of items above a particular header. i want to limit the range in which the user can drag items by two headers (above and below) . Between these two border headers are a lot of sections/headers where the user can organize stuff. If you have an alternative solution to get my intended behavior (in order to avoid the bug), I am also open to that alternatively I hope you understand what I mean. I tried to make my description as accurate and easy to understand as possible
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
@maltebucksch OK there’s no code, but what I said remains true: the item is still not moved and
getSectionIndex(toPosition)
cannot know that you are dragging(!): intoPosition
there’s still the header so it is counted in. You have to adapt your use case with a super simpleif
statement:With beta8 I can activate the
shouldMove
for the listener, I see that you use it.I’ve published the new SNAPSHOT with the
shouldMoveItem
callback, so you will have to implement it. If you have others callbacks customized you can extend your interface with the Adapter interfaceOnItemMoveListener
, so that you can continue to use it.