Handling drag-n-drop with shadow offset

418 Views Asked by At

I want to implement drag-n-drop with shadow offset, but there is a problem with Android framework's touch point calculation.

I've set a vertical offset with drag shadow builder:

        override fun onProvideShadowMetrics(outShadowSize: Point, outShadowTouchPoint: Point) {
            super.onProvideShadowMetrics(outShadowSize, outShadowTouchPoint)

            outShadowSize.set(dragParams.viewWidth, dragParams.viewHeight)

            outShadowTouchPoint.y = dragParams.viewVerticalOffset
        }

It looks like this:

enter image description here

At the first sight it works fine, until you approach top or bottom borders.

The framework calculates enter/exit/move events based on the finger location, not the shadow location. If we have an offset, we can calculate the shadow's centerY like this: val centerY = (rawY - viewVerticalOffset + viewHeight / 2).toInt(), but the framework, obviously, will still use finger position.

So, when we cross the bottom border with our finger, it would send an ACTION_DRAG_EXITED event, regardless of the shadow still being located within the drop target:

enter image description here

And if we're not crossing the top border with our finger, it still thinks, that the drag is still within the drop target's bounds (but the shadow is completely out of it):

enter image description here

So, if I want to implement the drag-n-drop with shadow's vertical offset, how should I do it?

0

There are 0 best solutions below