https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

03/24/2022, 5:00 AM
I updated to latest compose alpha and now I have this compile error regarding a
Card
My code
Copy code
Card(
    modifier = modifier,
    backgroundColor = color,
    onClick = onClick ?: {},
    indication = if (onClick == null) null else LocalIndication.current,
) { content() }
if I use the alt+enter helper it removes the
indication =...
. How can I set an indication on the card now though?
For now I just did this /shruggie
Copy code
if (onClick == null) {
  Card(modifier = modifier, backgroundColor = color) { content() }
} else {
  Card(onClick = onClick, modifier = modifier, backgroundColor = color) {
    content()
  }
}
l

Louis Pullen-Freilich [G]

03/24/2022, 2:13 PM
Indication was removed for consistency with other Material APIs - indication is an implementation detail here, as a Card should always use a ripple, in the same way Button will always have a ripple
In any case, your previous code probably doesn’t work as expected - the component would still appear clickable for accessibility, visible to focus traversal, consume input events, etc.
c

Colton Idle

03/24/2022, 2:51 PM
New code seems fine to you though?
l

Louis Pullen-Freilich [G]

03/24/2022, 2:53 PM
If the goal is to provide a single Card function that can switch between being clickable, and not-clickable, then yeah 🙂
1
z

Zach Klippenstein (he/him) [MOD]

03/24/2022, 3:04 PM
Your new code will lose any state inside your card if you switch between those if cases though. Consider putting
content
in a
movableContentOf
.
🤔 1
l

Louis Pullen-Freilich [G]

03/24/2022, 3:15 PM
True. Then again, I think it would be very unexpected to switch the same card between clickable and non-clickable - since there would be no visual indication that the card is now no longer clickable 🙂 So if you want to swap the same card, this probably is just going to be confusing for users
c

Colton Idle

03/24/2022, 7:14 PM
yeah. the "clickability" of a card can almost be guaranteed not to change. but now im intrigued by this whole movableContentOf business. 😄
💯 1
2 Views