Skip to content

Commit

Permalink
Library: Reduce items jank in RecyclerView (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid committed Nov 15, 2020
1 parent e5c7e31 commit 8da6108
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ class NeumorphShapeDrawable : Drawable {
}

override fun invalidateSelf() {
dirty = true
// To reduce jank in RecyclerView.
if (isVisibleChanging.not()) {
dirty = true
}
super.invalidateSelf()
}

Expand Down Expand Up @@ -265,6 +268,15 @@ class NeumorphShapeDrawable : Drawable {
&& strokePaint.strokeWidth > 0)
}

private var isVisibleChanging = false

override fun setVisible(visible: Boolean, restart: Boolean): Boolean {
isVisibleChanging = true
return super.setVisible(visible, restart).apply {
isVisibleChanging = false
}
}

override fun onBoundsChange(bounds: Rect) {
dirty = true
super.onBoundsChange(bounds)
Expand Down Expand Up @@ -324,7 +336,12 @@ class NeumorphShapeDrawable : Drawable {
CornerFamily.ROUNDED -> {
path.addRoundRect(
left, top, right, bottom,
shapeAppearanceModel.getCornerRadii(min(bounds.width() / 2f, bounds.height() / 2f)),
shapeAppearanceModel.getCornerRadii(
min(
bounds.width() / 2f,
bounds.height() / 2f
)
),
Path.Direction.CW
)
}
Expand Down

0 comments on commit 8da6108

Please sign in to comment.