Skip to content

Instantly share code, notes, and snippets.

@Levi-Moreira
Last active February 12, 2024 08:07
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 Levi-Moreira/360f7bdb39c1fb44288b3437a53a9651 to your computer and use it in GitHub Desktop.
Save Levi-Moreira/360f7bdb39c1fb44288b3437a53a9651 to your computer and use it in GitHub Desktop.
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