This is my simplified code:
val scrollBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior()
val isCollapsed = scrollBehavior.state.collapsedFraction != 1.0f
val listState = rememberLazyListState()
Scaffold(
contentWindowInsets = WindowInsets(0, 0, 0, 0),
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
bottomBar = {
AnimatedVisibility(!listState.canScrollBackward || !isCollapsed) {
BottomAppBar(scrollBehavior = scrollBehavior) {
//...
Button(onClick = {
scope.launch {
listState.animateScrollToItem(0)
}
}) {
Text("Scroll to top")
}
}
}
}
)
isCollapsed
and !listState.canScrollBackward
is used to determine whether the BottomAppBar should be displayed.
I saw such an implementation on issuetracker. But it not works for me.
Source: View source