Last active
July 13, 2022 06:00
-
-
Save hkawii/8e55a6e4ed5144510c6c933f0cc9fb8d 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
@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