Skip to content

Instantly share code, notes, and snippets.

@mazzouzi
Last active September 24, 2022 11:49
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 mazzouzi/bdd6522b2e0a4299736e72ca3ea2c37a to your computer and use it in GitHub Desktop.
Save mazzouzi/bdd6522b2e0a4299736e72ca3ea2c37a to your computer and use it in GitHub Desktop.
Title scale animation
private const val titleFontScaleStart = 1f
private const val titleFontScaleEnd = 0.66f
@Composable
private fun Title(scroll: ScrollState, headerHeightPx: Float, toolbarHeightPx: Float) {
val collapseRange: Float = (headerHeightPx - toolbarHeightPx)
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
val scaleXY = lerp(
titleFontScaleStart.dp,
titleFontScaleEnd.dp,
collapseFraction
)
Text(
text = "New York",
fontSize = 30.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier
.graphicsLayer {
// if scaleXY equals 0.8.dp then scaleXY.value equals 0.8
scaleX = scaleXY.value
scaleY = scaleXY.value
}
)
.
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment