Skip to content

Instantly share code, notes, and snippets.

@hkawii
Last active July 13, 2022 06:00
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 hkawii/8e55a6e4ed5144510c6c933f0cc9fb8d to your computer and use it in GitHub Desktop.
Save hkawii/8e55a6e4ed5144510c6c933f0cc9fb8d to your computer and use it in GitHub Desktop.
@Composable
fun SectionTextView(
modifier: Modifier = Modifier,
text: String,
isSelected: Boolean
) {
Column(modifier) {
var textWidth by remember { mutableStateOf(0.dp) }
val density = LocalDensity.current
Text(
modifier = Modifier.onGloballyPositioned {
textWidth = with(density) { it.size.width.toDp() } //update text width value according to the content size
},
text = text,
style = TextStyle(fontSize = 24.sp, fontWeight = FontWeight.Bold),
color = if (isSelected) Purple200 else Color.DarkGray
)
//Show the text underline with animation
AnimatedVisibility(
visible = isSelected,
enter = expandHorizontally() + fadeIn(),
exit = shrinkHorizontally() + fadeOut()
) {
Box(
Modifier
.width(textWidth)
.padding(top = 15.dp)
.height(3.dp)
.background(Purple200)
) {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment