Closed JimVanG closed 3 years ago
This solution is nice because it doesn't go through the entire draw process when it doesn't need to.
This modification leads to visual artifacts: when the view is animating back to its original state no icon nor background will be drawn.
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.
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)
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.