nlindberg
08/20/2021, 1:42 PMStylianos Gakis
08/21/2021, 1:16 PMprivate operator fun Color.inc(): Color {
// Or by a nicer amount. Maybe consider making it follow the rainbow colors? Not sure what the sequence Flutter colors follow for this.
fun Float.increaseColorByLittle(): Float =
(this + 0.02f).coerceAtMost(1f)
// Or actually make this look nicer
return when {
red != 1f -> this.copy(red = red.increaseColorByLittle())
green != 1f -> this.copy(green = green.increaseColorByLittle())
blue != 1f -> this.copy(blue = blue.increaseColorByLittle())
else -> Color(red = 0f, green = 0f, blue = 0f)
}
}
fun Modifier.indicateRecompositions(width: Dp = 20.dp): Modifier = composed {
var color by remember { mutableStateOf(Color(red = 255, green = 0, blue = 0, alpha = 128)) }
SideEffect {
color++
}
this.then(
Modifier
.drawWithContent {
drawContent()
val topLeftOffset = Offset(width.toPx() / 2, width.toPx() / 2)
drawRect(
color = color,
style = Stroke(width = width.toPx()),
topLeft = topLeftOffset,
// Size adjustments to make it be *inside* the composable instead of stroking along the edges
size = Size(
width = size.width - (topLeftOffset.x * 2),
height = size.height - (topLeftOffset.y * 2),
)
)
}
)
}
And then just add it to any of your composables like
modifier = Modifier.indicateRecompositions()
And it should change the color slightly whenever a recomposition happens. Feel free to adjust all the values to get a better feeling of it.Stylianos Gakis
08/22/2021, 10:01 AMnlindberg
08/22/2021, 10:03 AMStylianos Gakis
03/14/2022, 9:48 PM