From 2a6474988a007f1437d916268128720fd7fad0b6 Mon Sep 17 00:00:00 2001 From: Tamim Attafi Date: Sat, 20 Feb 2021 00:16:30 -0800 Subject: [PATCH] Library: Added drawable invalidation --- .../soup/neumorphism/NeumorphShapeDrawable.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt b/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt index 15c29bf..e35a907 100644 --- a/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt +++ b/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt @@ -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 @@ -140,7 +140,7 @@ class NeumorphShapeDrawable : Drawable { override fun setAlpha(alpha: Int) { if (drawableState.alpha != alpha) { drawableState.alpha = alpha - invalidateSelf() + invalidateSelfIgnoreShape() } } @@ -229,7 +229,7 @@ class NeumorphShapeDrawable : Drawable { fun setTranslationZ(translationZ: Float) { if (drawableState.translationZ != translationZ) { drawableState.translationZ = translationZ - invalidateSelf() + invalidateSelfIgnoreShape() } } @@ -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 {