Skip to content

Instantly share code, notes, and snippets.

@KlassenKonstantin
Created October 1, 2023 17:42
Show Gist options
  • Save KlassenKonstantin/b2c31316c07495bb85931a42ad67fa11 to your computer and use it in GitHub Desktop.
Save KlassenKonstantin/b2c31316c07495bb85931a42ad67fa11 to your computer and use it in GitHub Desktop.
Cascading Text Transition
@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