In Jetpack Compose, when you enable clickable {}
on a modifier for a composable, by default it enables ripple effect for it. How to disable this behavior?
Example code
Row(modifier = Modifier .clickable { // action } )
if you are using modifier clickable attribute on Column or any other component then you can use enabled attribute along with onClick to disable ripple effect when needed.
A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.
mutableStateOf creates an observable MutableState<T> , which is an observable type integrated with the compose runtime. Any changes to value will schedule recomposition of any composable functions that read value . In the case of ExpandingCard , whenever expanded changes, it causes ExpandingCard to be recomposed.
Short answer:
to disable the ripple pass null
in the indication
parameter in the clickable
modifier:
val interactionSource = remember { MutableInteractionSource() } Column { Text( text = "Click me and my neighbour will indicate as well!", modifier = Modifier .clickable( interactionSource = interactionSource, indication = null ) { /* .... */ } )
Long answer:
If you add the clickable
modifier to the element to make it clickable within its bounds it will show an Indication
as specified in indication parameter.
By default, indication from LocalIndication
will be used.
If you are using a MaterialTheme
in your hierarchy, a Ripple
will be used as the default Indication
inside components such as androidx.compose.foundation.clickable
and androidx.compose.foundation.indication
.
Use this Modifier extension:
inline fun Modifier.noRippleClickable(crossinline onClick: ()->Unit): Modifier = composed { clickable(indication = null, interactionSource = remember { MutableInteractionSource() }) { onClick() } }
then simply replace Modifier.clickable {}
with Modifier.noRippleClickable {}
Row(modifier = Modifier.noRippleClickable { // action })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With