Created
October 1, 2023 17:42
-
-
Save KlassenKonstantin/b2c31316c07495bb85931a42ad67fa11 to your computer and use it in GitHub Desktop.
Cascading Text Transition
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 TextTransition(textAndColor: Pair<String, Color>) { | |
AnimatedContent( | |
targetState = textAndColor, | |
transitionSpec = { | |
fadeIn() togetherWith fadeOut() | |
} | |
) { (text, color) -> | |
Row { | |
text.forEachIndexed { index, char -> | |
val stiffness = 300f - 200f * (index.toFloat() / (text.length - 1)) | |
Text( | |
modifier = Modifier.animateEnterExit( | |
enter = slideInVertically(spring(dampingRatio = 0.7f, stiffness = stiffness)) { -it }, | |
exit = slideOutVertically { it } | |
), | |
text = char.toString(), | |
style = MaterialTheme.typography.titleLarge, | |
fontWeight = FontWeight.Medium, | |
color = color | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment