mochixuan/react-native-drag-sort

Bounds for item drag zone are not always correct

Closed this issue · 4 comments

Hi, I found another slightly odd bug with the library. I've noticed that in certain circumstances it is possible to drag the tiles outside of the bounds of the container. I've used a very simple sample app to demonstrate - https://github.com/avertin/reorder-sample

If you rotate to landscape, scroll a little, then try to drag an item. You will notice that it is possible to drag the item far above the top of the container so it almost disappears from the view.

Screen Recording 2021-01-08 at 12 04 33 PM

I found the section of code that I think is causing the problem - https://github.com/mochixuan/react-native-drag-sort/blob/master/lib/AutoDragSortableView.js#L266

if (!this.isStartupAuto()) {
    if (this.touchCurItem.originTop + dy < 0) {
        dy = -this.touchCurItem.originTop
    } else if (this.touchCurItem.originTop + dy > maxHeight) {
        dy = maxHeight - this.touchCurItem.originTop
    }
}

I think the bug is that the vertical bound checks don't apply if this.isStartupAuto() is true. Hence why the bug only reproduces after the component has been scrolled.

I still haven't figured out a fix, but I'd be curious to hear if you have any ideas.

After reading my Demo, it can't be drawn out. You can see if there is a problem with your width setting. Or you can run Example to see the effect

I can confirm that this happens on your sample app too. After scrolling, it is possible to drag an element far beyond the top bound.

ezgif-6-78d80562085c

Yes, this one can be dragged up to start the automatic sliding function, but it will automatically reset to the normal position when you let go