Skip to content

Commit

Permalink
Library: Added drawable invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamim Attafi authored and Tamim Attafi committed Feb 20, 2021
1 parent cfcdbc2 commit 2a64749
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NeumorphShapeDrawable : Drawable {

private var drawableState: NeumorphShapeDrawableState

private var dirty = true
private var dirty = false

private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
Expand Down Expand Up @@ -140,7 +140,7 @@ class NeumorphShapeDrawable : Drawable {
override fun setAlpha(alpha: Int) {
if (drawableState.alpha != alpha) {
drawableState.alpha = alpha
invalidateSelf()
invalidateSelfIgnoreShape()
}
}

Expand Down Expand Up @@ -229,7 +229,7 @@ class NeumorphShapeDrawable : Drawable {
fun setTranslationZ(translationZ: Float) {
if (drawableState.translationZ != translationZ) {
drawableState.translationZ = translationZ
invalidateSelf()
invalidateSelfIgnoreShape()
}
}

Expand All @@ -241,13 +241,22 @@ class NeumorphShapeDrawable : Drawable {
setTranslationZ(z - getShadowElevation())
}

override fun invalidateSelf() {
dirty = true
super.invalidateSelf()
}

private fun invalidateSelfIgnoreShape() {
super.invalidateSelf()
}

fun getPaintStyle(): Paint.Style? {
return drawableState.paintStyle
}

fun setPaintStyle(paintStyle: Paint.Style) {
drawableState.paintStyle = paintStyle
invalidateSelf()
invalidateSelfIgnoreShape()
}

private fun hasBackgroundBitmap(): Boolean {
Expand Down

0 comments on commit 2a64749

Please sign in to comment.