JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.26k stars 1.18k forks source link

How to remove ripple effect on Modifier.clickable() #475

Closed smallshen closed 3 years ago

smallshen commented 3 years ago

How to remove ripple effect on Modifier.clickable()

igordmn commented 3 years ago

Try this:

Modifier.clickable(interactionSource = remember(::MutableInteractionSource), indication = null)

@jimgoog, disabling the indication is a little verbose now :). What do you think about adding an overload of clickable without interactionSource parameter?

fun Modifier.clickable(
    indication: Indication?,
    enabled: Boolean = true,
    onClickLabel: String? = null,
    role: Role? = null,
    onClick: () -> Unit
)= composed(
    inspectorInfo = debugInspectorInfo {
        name = "clickable"
        properties["enabled"] = enabled
        properties["onClickLabel"] = onClickLabel
        properties["role"] = role
        properties["onClick"] = onClick
    }
) {
    Modifier.clickable(
        enabled = enabled,
        onClickLabel = onClickLabel,
        onClick = onClick,
        role = role,
        indication = indication,
        interactionSource = remember { MutableInteractionSource() }
    )
}

Not so long ago interactionSource was with a default value: https://android-review.googlesource.com/c/platform/frameworks/support/+/1544584/5/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Clickable.kt#b64

smallshen commented 3 years ago

Thank you, it works.

jimgoog commented 3 years ago

I believe the ripple animation is setup when MaterialTheme is installed, which seems appropriate, and LocalIndication can be used to override this default behavior across the hierarchy. Users can also work around the verbosity by creating their own overload.

That said, I don't see a reason why Modifier.clickable's interactionSource parameter doesn't have a default value of remember { MutableInteractionSource() } instead forcing users to pass it in when they want to override the indication parameter. I will raise this with API Council and see if I'm missing something. @igordmn - Thanks for pointing it out as an opportunity for polish.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.