KotlinLeaner
07/29/2022, 2:29 PMbinding.itemComposable.setContent {
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val backgroundColor = if (isPressed) DuckEggBlue else OffWhite
val clickable = Modifier.clickable(
interactionSource = interactionSource,
indication = LocalIndication.current
) {
println("Item Click")
}
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
val options = getOptions()
options.forEachIndexed { _, optionText ->
Card(
shape = RoundedCornerShape(4.dp),
modifier = Modifier.then(clickable)
) {
Text(
modifier = Modifier
.fillMaxWidth()
.background(backgroundColor)
.padding(16.dp),
text = optionText,
style = Typography.h3,
fontWeight = FontWeight.Medium,
color = Slate
)
}
}
}
}
Stylianos Gakis
07/29/2022, 3:26 PMval interactionSource
until before Column
to inside the lambda options.forEachIndexed {
so each item gets its own instance.KotlinLeaner
07/29/2022, 3:27 PMStylianos Gakis
07/29/2022, 3:28 PMYou could move the block fromuntil beforeval interactionSource
to inside the lambdaColumn
so each item gets its own instance.options.forEachIndexed {
KotlinLeaner
07/29/2022, 3:28 PM