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/8566f4dee7c6a566f1c7fe59c0d267ad to your computer and use it in GitHub Desktop.
Save mazzouzi/8566f4dee7c6a566f1c7fe59c0d267ad to your computer and use it in GitHub Desktop.
Bernstein polynomial form
.
.
Text(
text = "New York",
fontSize = 30.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier
.graphicsLayer {
val collapseRange: Float = (headerHeightPx - toolbarHeightPx)
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
val titleY: Float = (1f-collapseFraction).pow(2) *
(headerHeightPx - titleHeightPx - paddingPx) +
2 * collapseFraction * (1-collapseFraction) * headerHeightPx / 2 +
collapseFraction.pow(2) * (toolbarHeightPx / 2 - titleHeightPx / 2)
val titleX: Float =
(1f-collapseFraction).pow(2) * (titlePaddingStartPx) +
2 * collapseFraction * (1-collapseFraction) * titlePaddingEndPx *
5 / 4 + collapseFraction.pow(2) * titlePaddingEndPx
translationY = titleY
translationX = titleX
}
.onGloballyPositioned {
titleHeightPx = it.size.height.toFloat()
}
)
.
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment