eschrag
04/01/2021, 6:01 PMZach Klippenstein (he/him) [MOD]
04/01/2021, 6:17 PMeschrag
04/01/2021, 6:29 PMColton Idle
04/01/2021, 6:34 PMColton Idle
04/01/2021, 6:35 PMeschrag
04/01/2021, 6:37 PM@Stable
interface ButtonColors {
/**
* Represents the background color for this button, depending on [enabled].
*
* @param enabled whether the button is enabled
*/
@Composable
fun backgroundColor(enabled: Boolean): State<Color>
/**
* Represents the content color for this button, depending on [enabled].
*
* @param enabled whether the button is enabled
*/
@Composable
fun contentColor(enabled: Boolean): State<Color>
}
and i’m not sure how to make an impl of this interface respect the interactionSource to get that PRESSED info in and updatedeschrag
04/01/2021, 6:38 PMprivate class OurButtonColors(val pressed: State<Boolean>) : ButtonColors {
@Composable
override fun backgroundColor(enabled: Boolean): State<Color> {
return if (pressed.value) {
rememberUpdatedState(newValue = Color.Red)
} else {
rememberUpdatedState(newValue = Color.Magenta)
}
}
@Composable
override fun contentColor(enabled: Boolean): State<Color> {
return rememberUpdatedState(newValue = Color.Green)
}
}
and passed it `
val isPressed = interactionSource.collectIsPressedAsState()
`eschrag
04/01/2021, 6:38 PMColton Idle
04/01/2021, 6:44 PMColton Idle
04/01/2021, 6:51 PMZach Klippenstein (he/him) [MOD]
04/01/2021, 6:53 PMIndication
. https://developer.android.com/reference/kotlin/androidx/compose/foundation/IndicationLouis Pullen-Freilich [G]
04/01/2021, 7:07 PMi just want to replicate the old state list behavior. if button is pressed, button background color is blue, otherwise it’s teal. no ripple at all.At this point it is probably easier just to build your own button, since ripple is a core part of Material components. Then you can just do:
val isPressed = interactionSource.collectIsPressedAsState()
val backgroundColor = if (isPressed) .. else ..
Surface(backgroundColor...)
Zach Klippenstein (he/him) [MOD]
04/01/2021, 8:22 PMLouis Pullen-Freilich [G]
04/01/2021, 9:51 PMeschrag
04/02/2021, 1:54 AMinteractionSource = interactionSource,
in the Composable call