nemanja-kovacevic / recycler-view-swipe-to-delete

Sample project showing "swipe to delete" on a recycler view with no 3rd parties involved. It also include drawing on empty space while items are animating and an "undo" option
334 stars 96 forks source link

Don't render the icon when swipe event aborted. #6

Closed JimVanG closed 3 years ago

JimVanG commented 7 years ago

When the user aborts a swipe event (i.e. they don't swipe all the way to the left or if they drag the item back to the right) the icon/drawable still remains rendered in on the item. This bug has been fixed.

JimVanG commented 7 years ago

This solution is nice because it doesn't go through the entire draw process when it doesn't need to.

a-ch commented 7 years ago

This modification leads to visual artifacts: when the view is animating back to its original state no icon nor background will be drawn.

JimVanG commented 6 years ago

I'm not sure what you're talking about....

Without the modification the icon will remain rendered on top of the list item, something that you do not want.

With this modification the item's original state Is preserved, and you can still re-swipe and there's still an animation.

Matungos commented 4 years ago

I've fixed that issue doing this:

if (isCurrentlyActive) {
    // draw x mark
    val itemHeight = itemView.bottom - itemView.top
    val intrinsicWidth = xMark.intrinsicWidth
    val intrinsicHeight = xMark.intrinsicWidth
    val xMarkLeft = (itemView.right - xMarkMargin - intrinsicWidth).toInt()
    val xMarkRight = itemView.right - xMarkMargin.toInt()
    val xMarkTop = itemView.top + (itemHeight - intrinsicHeight) / 2
    val xMarkBottom = xMarkTop + intrinsicHeight
    xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom)
    xMark.draw(c)
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)