Skip to content

Instantly share code, notes, and snippets.

@AlShevelev
Created July 16, 2022 12:44
Show Gist options
  • Save AlShevelev/bf9836112b10b1c496aa3c1004b0576a to your computer and use it in GitHub Desktop.
Save AlShevelev/bf9836112b10b1c496aa3c1004b0576a to your computer and use it in GitHub Desktop.
@Composable
internal fun Root() {
val toolbarHeightPx = remember { mutableStateOf(0f) }
val topPanelOffset = remember { mutableStateOf(0f) }
Scaffold(
topBar = {
TopBarFixed(
maxOffset = toolbarHeightPx.value,
currentOffset = topPanelOffset.value
)
}
) {
CoordinatedScroll(
collapsingAreaHeightPx = toolbarHeightPx
) { offset, nestedScroll ->
topPanelOffset.value = offset
Box(
Modifier
.fillMaxSize()
.nestedScroll(nestedScroll)
) {
TopBarCollapsing(
currentOffset = offset,
maxOffset = toolbarHeightPx.value,
modifier = Modifier
.zIndex(1f)
.fillMaxWidth(),
onHeightCalculated = {
toolbarHeightPx.value = it
}
)
val contentPadding = with(LocalDensity.current) {
toolbarHeightPx.value.toInt().toDp() - abs(offset).toDp()
}
ScrollableContent(
contentTopPadding = contentPadding,
modifier = Modifier
.padding(top = 16.dp)
.fillMaxSize()
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment