Created
March 17, 2024 03:40
-
-
Save fvilarino/61b3308df9cd24e11cdabdbe8b1c7cf9 to your computer and use it in GitHub Desktop.
Chip Selector - Text Alpha
This file contains hidden or 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
@Composable | |
fun Chip( | |
label: String, | |
isSelected: Boolean, | |
onClick: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
val transition = updateTransition(targetState = isSelected, label = "transition") | |
// 1 | |
val textAlpha by transition.animateFloat( | |
transitionSpec = { tween(durationMillis = AnimationDurationMillis) }, | |
label = "textAlpha" | |
) { selected -> | |
if (selected) 1f else .6f | |
} | |
Box( | |
modifier = modifier | |
.drawWithCache { | |
... | |
} | |
.clickable(interactionSource = interactionSource, indication = null, onClick = onClick) | |
) { | |
Text( | |
text = label, | |
color = textColor, | |
fontWeight = FontWeight.Bold, | |
modifier = Modifier | |
.padding(horizontal = 24.dp, vertical = 16.dp) | |
// 2 | |
.graphicsLayer { alpha = textAlpha } | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment