ascii
09/06/2023, 9:49 PMerror
, similar to a progress bar filling up. What I have here works, but I was wondering if there's a better way to do it. Reliability/performance.
val animationState = remember { AnimationState(0f) }
LaunchedEffect(Unit) { animationState.animateTo(1f, tween(5000)) }
val disabled = MaterialTheme.colorScheme.onSurface.copy(0.38f)
val error = MaterialTheme.colorScheme.error
val offset = animationState.value
val brush = remember(error, disabled, offset) {
object : ShaderBrush() {
override fun createShader(size: Size) = LinearGradientShader(
from = Offset.Zero,
to = Offset(size.width * offset, 0f),
colors = listOf(error, disabled),
colorStops = listOf(offset, 1f),
)
}
}
TextButton(
enabled = offset >= 1f,
colors = ButtonDefaults.textButtonColors(contentColor = error)
) { Text(style = LocalTextStyle.current.copy(brush)) }
ascii
09/06/2023, 9:51 PMcah
09/07/2023, 1:10 AMromainguy
09/07/2023, 3:24 AMascii
09/07/2023, 1:25 PM