Is it possible to override a child composables onc...
# compose
z
Is it possible to override a child composables onclick & ripple effect if its a button? In my scenario, a button is placed at the bottom of a card with padding around it; Id like the clickable area to cover the entire width of the card (similar to what could be acheived by specifying
selectableItemBackground
on the parent rather than child view in XML). If I specify a clickable composable around the button, the button will still grab focus (even if I mute its ripple effect through
Modifier.clickable
). I can acheive it by using a
Text
instead of
Button
since it wouldnt be clickable, but then Id have to continiously mimic the button style exactly in the text composable.
z
Do you not want a
TextButton
?
z
I do, but I'm using padding around it to get the right alignment and the click area naturally follows the padding whereas I'd like it to cover the entire row. I couldn't capture the click in the screenshot but there's a 8.dp padding around the text button.
f
The button receives a
contentPadding
argument, with which you can apply padding to the clickable area.
z
You could also try customizing the Indication. The foundation-level components take it explicitly but you’d need to specify LocalIndication to override it for material buttons.
z
@Felix Schütz Thanks for reminding me about it! It makes the button larger though, and Im really after making the entire row clickable while keeping the button the same default size. @Zach Klippenstein (he/him) [MOD] Thanks, I just tried that by wrapping the button in a
CompositionLocal
and providing a different indication (copy of
NoIndication
) but the original ripple was still there. Following the same route, I also tried specifying a custom
MutableInteractionSource
which didnt emit anything, this stopped the ripple effects, but the button is still clickable. Effectively I can get the whole area to be clickable with the proper ripple effect now, but the buttons area will still steal the click event.