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
val titleYFirstInterpolatedPoint = lerp( | |
headerHeight - titleHeightDp - paddingMedium, | |
headerHeight / 2, | |
collapseFraction | |
) |
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 | |
private fun Title(scroll: ScrollState, headerHeightPx: Float, toolbarHeightPx: Float) { | |
var titleHeightPx by remember { mutableStateOf(0f) } | |
val titleHeightDp = with(LocalDensity.current) { titleHeightPx.toDp() } | |
Text( | |
text = "New York", | |
fontSize = 30.sp, | |
fontWeight = FontWeight.Bold, | |
modifier = Modifier |
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
val collapseRange: Float = (headerHeightPx - toolbarHeightPx) | |
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f) |
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 | |
private fun Toolbar(scroll: ScrollState, headerHeightPx: Float, toolbarHeightPx: Float) { | |
val toolbarBottom = headerHeightPx - toolbarHeightPx | |
val showToolbar by remember { | |
derivedStateOf { scroll.value >= toolbarBottom } | |
} | |
AnimatedVisibility( | |
visible = showToolbar, | |
enter = fadeIn(animationSpec = tween(300)), |
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 | |
private fun Header(scroll: ScrollState, headerHeightPx: Float) { | |
Box(modifier = Modifier | |
.fillMaxWidth() | |
.height(headerHeight) | |
.graphicsLayer { | |
alpha = (-1f / headerHeightPx) * scroll.value + 1 | |
} | |
) | |
. |
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 | |
private fun Title() { | |
Text( | |
text = "New York", | |
fontSize = 30.sp, | |
fontWeight = FontWeight.Bold | |
) | |
} |
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 | |
private fun Toolbar() { | |
TopAppBar( | |
modifier = Modifier.background( | |
brush = Brush.horizontalGradient( | |
listOf(Color(0xff026586), Color(0xff032C45)) | |
) | |
), | |
navigationIcon = { | |
IconButton( |
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 | |
private fun Header(scroll: ScrollState, headerHeightPx: Float) { | |
Box(modifier = Modifier | |
.fillMaxWidth() | |
.height(headerHeight) | |
.graphicsLayer { | |
translationY = -scroll.value.toFloat() / 2f // Parallax effect | |
} | |
) |
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 | |
private fun Body(scroll: ScrollState) { | |
Column( | |
horizontalAlignment = Alignment.CenterHorizontally, | |
modifier = Modifier.verticalScroll(scroll) | |
) | |
. | |
. |
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
val scroll: ScrollState = rememberScrollState(0) |