Last active
February 12, 2024 08:07
-
-
Save Levi-Moreira/360f7bdb39c1fb44288b3437a53a9651 to your computer and use it in GitHub Desktop.
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
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
val appBarMaxHeightPx = with(LocalDensity.current) { AppBarHeight.roundToPx() } | |
val connection = remember(appBarMaxHeightPx) { | |
CollapsingAppBarNestedScrollConnection(appBarMaxHeightPx) | |
} | |
val density = LocalDensity.current | |
val spaceHeight by remember(density) { | |
derivedStateOf { | |
with(density) { | |
(appBarMaxHeightPx + connection.appBarOffset).toDp() | |
} | |
} | |
} | |
Box(Modifier.nestedScroll(connection)) { | |
Column { | |
Spacer( | |
Modifier | |
.padding(4.dp) | |
.height(spaceHeight) | |
) | |
LazyColumn { | |
items(Contents) { | |
ListItem(item = it) | |
} | |
} | |
} | |
TopAppBar( | |
modifier = Modifier.offset { IntOffset(0, connection.appBarOffset) }, | |
title = { Text(text = "Jetpack Compose") }, | |
colors = TopAppBarDefaults.topAppBarColors( | |
containerColor = Purple40, | |
titleContentColor = Color.White | |
) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment