josefdolezal
09/03/2021, 9:05 PMButtons
colors based on enabled
? What comes to my mind is to create my own class implementing ButtonColors
which would then animate the color using animateColorAsState
, but it seems a bit too verboseRob Meeuwisse
09/05/2021, 6:39 PM@Composable
private fun rememberButtonColors(
interactionSource: InteractionSource,
backgroundColorPressed: Color,
backgroundColorNormal: Color,
contentColorPressed: Color,
contentColorNormal: Color,
): ButtonColors = remember(
interactionSource,
backgroundColorPressed,
backgroundColorNormal,
contentColorPressed,
contentColorNormal,
) {
object : ButtonColors {
private val isPressed
@Composable get() = interactionSource.collectIsPressedAsState().value
@Composable
override fun backgroundColor(enabled: Boolean): State<Color> = animateColorAsState(...) // calc color dependant on state
// etc.
}
}
josefdolezal
09/10/2021, 9:07 PMCrossfade
two buttons:
@Composable
fun AnimatedButton(isEnabled: Boolean = true) = Crossfade(targetState = isEnabled) { isEnabled ->
Button(enabled = isEnabled)
}