Skip to content

Commit aade8e8

Browse files
javachefacebook-github-bot
authored andcommitted
Fix infinite invalidation of vector drawabables
Reviewed By: oprisnik Differential Revision: D66537189 fbshipit-source-id: 6dfe03786bc1f97123f9e6790ed9f8eaccb91a94
1 parent 18e838b commit aade8e8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎vito/renderer/src/main/java/com/facebook/fresco/vito/renderer/ImageRenderer.kt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import android.graphics.Canvas
1313
import android.graphics.Matrix
1414
import android.graphics.Paint
1515
import android.graphics.Shader
16+
import android.os.Build
1617
import com.facebook.fresco.vito.renderer.util.ColorUtils
1718

1819
typealias RenderCommand = (Canvas) -> Unit
@@ -83,14 +84,21 @@ object ImageRenderer {
8384
shape.rect.right.toInt(),
8485
shape.rect.bottom.toInt())
8586
}
86-
drawable.colorFilter = paint.colorFilter
87+
// Some drawable types (eg VectorDrawable) will always invalidate when colorFilter
88+
// is modified, so check the current value before we update it
89+
if (Build.VERSION.SDK_INT < 21 || drawable.colorFilter != paint.colorFilter) {
90+
drawable.colorFilter = paint.colorFilter
91+
}
8792
drawable.alpha = paint.alpha
8893
drawable.draw(canvas)
8994
}
9095
else -> {
9196
return { canvas ->
9297
drawable.setBounds(0, 0, width, height)
93-
drawable.colorFilter = null // The Paint handles the color filter
98+
if (Build.VERSION.SDK_INT < 21 || drawable.colorFilter != null) {
99+
// The Paint handles the color filter
100+
drawable.colorFilter = null
101+
}
94102
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
95103
drawable.draw(Canvas(bitmap))
96104
paint.setBitmap(bitmap, imageTransformation)

0 commit comments

Comments
 (0)