Last active
June 7, 2023 14:05
-
-
Save PhilipDukhov/c344a8773fea0fea0bef1cbaf0b141c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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