Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created March 17, 2024 03:40
Show Gist options
  • Save fvilarino/61b3308df9cd24e11cdabdbe8b1c7cf9 to your computer and use it in GitHub Desktop.
Save fvilarino/61b3308df9cd24e11cdabdbe8b1c7cf9 to your computer and use it in GitHub Desktop.
Chip Selector - Text Alpha
@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