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:
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:
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):
So, if I want to implement the drag-n-drop with shadow's vertical offset, how should I do it?