Skip to content

Instantly share code, notes, and snippets.

@PhilipDukhov
Last active June 7, 2023 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhilipDukhov/c344a8773fea0fea0bef1cbaf0b141c8 to your computer and use it in GitHub Desktop.
Save PhilipDukhov/c344a8773fea0fea0bef1cbaf0b141c8 to your computer and use it in GitHub Desktop.
fun Modifier.clickableClipped(
shape: Shape,
enabled: Boolean = true,
onClickLabel: String? = null,
role: Role? = null,
onClick: () -> Unit,
) = composed {
val interactionSource = remember {
MutableInteractionSource()
}
val localIndication = LocalIndication.current
val density = LocalDensity.current
clickable(
interactionSource = interactionSource,
enabled = enabled,
onClickLabel = onClickLabel,
role = role,
onClick = onClick,
indication = remember(localIndication) {
object : Indication {
@Composable
override fun rememberUpdatedInstance(interactionSource: InteractionSource): IndicationInstance {
val indication = localIndication.rememberUpdatedInstance(interactionSource = interactionSource)
return remember(indication) {
object : IndicationInstance {
override fun ContentDrawScope.drawIndication() {
clipPath(
Path().apply {
addOutline(shape.createOutline(size, layoutDirection, density))
}
) {
with(indication) {
this@drawIndication.drawIndication()
}
}
}
}
}
}
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment