1

by default it enables ripple effect for it. How to disable this behavior?

IconButton(onClick = {}) {
}


Example code.

Kawan MC
  • 33
  • 4
  • Check also https://stackoverflow.com/questions/66703448/how-to-disable-ripple-effect-when-clicking-in-jetpack-compose/66703893#66703893 – Gabriele Mariotti May 17 '23 at 07:19

1 Answers1

1

IconButton is nothing other than Box with Modifier.clickable with ripple with 24.dp and 48.dp min size.

You can set copy source code and set indication null as

@Composable
fun IconButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    content: @Composable () -> Unit
) {
    Box(
        modifier = modifier
            .minimumInteractiveComponentSize()
            .clickable(
                onClick = onClick,
                enabled = enabled,
                role = Role.Button,
                interactionSource = interactionSource,
                //  Set this to null to remove ripple on touch
                indication = rememberRipple(bounded = false, radius = RippleRadius)
            ),
        contentAlignment = Alignment.Center
    ) {
        val contentAlpha = if (enabled) LocalContentAlpha.current else ContentAlpha.disabled
        CompositionLocalProvider(LocalContentAlpha provides contentAlpha, content = content)
    }
}

// Default radius of an unbounded ripple in an IconButton
private val RippleRadius = 24.dp

Or you can use a Box with Modifier.clickable if you don't need other params

Thracian
  • 43,021
  • 16
  • 133
  • 222