Created
July 16, 2022 12:44
-
-
Save AlShevelev/bf9836112b10b1c496aa3c1004b0576a 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
@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