Last active
September 24, 2022 11:49
-
-
Save mazzouzi/bdd6522b2e0a4299736e72ca3ea2c37a to your computer and use it in GitHub Desktop.
Title scale animation
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
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