I have a recycler view with ItemTouchHelper. It allows dragging the items.
I want to limit the dragging to the bounds of recycler view - i.e. you can't just drag the view outside the container, so that it disappears.
I tried checking the absolute coordinates like this:
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
recyclerView.getLocationOnScreen(pos);
int rvY = pos[1];
viewHolder.itemView.getLocationOnScreen(pos);
int vhY = pos[1];
if (rvY > vhY || rvY + recyclerView.getHeight() < vhY + viewHolder.itemView.getHeight()) {
return;
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
...
}
but then I run into kinda rendering concurency - if I move the view slowly, it will stop moving when going out of bounds, but if I move faster - then it anyway leaves the recycler view bounds.
Any ideas / approaches?