Follow-up related question... When using a LazyCol...
# compose
c
Follow-up related question... When using a LazyColumn as the content for a Scaffold with enterAlwaysScrollBehavior() - is it possible to reveal the TopAppBar when using automated scrolling? Following the above example, I issue a scroll request with a lanuched effect when the navbaritem is clicked...
Copy code
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
Scaffold(
    modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
    topBar = { TopAppBar(scrollBehavior = scrollBehavior, title =  {...})
) { paddingValues ->

    val state = rememberLazyListState()
    LaunchedEffect(...) { state.animateScrollToItem(0) }
    LazyColumn(state = state) {...}
}
The scroll position is moved to the top as expected. However, the upwards scroll doesn't seem to trigger the enterAlwaysScrollBehavior for revealing the TopAppBar again
t
Unfortunately no, you need to manuall call the nestedScrollConnection functions to simulate that.
c
ok interesting... so I would want to pass a lambda to my launchedEffect that includes some instruction for the nested connection to consume some scroll?
Copy code
LaunchedEffect(...) { 
    scrollBehavior.nestedScrollConnection.onPreScroll(Offset.Infinite, NestedScrollSource.SideEffect) 
    state.animateScrollToItem(0) 
}
t
Don't know the best way with TopAppbar, but if there's a state or other ways to directly control it, then it's better to use that. But faking nestedScroll usually works (I use that for other custom components, but no reason it does not work here too)
👍 1
c
ok nice, that's very helpful!
t
Maybe @Andrey Kulikov knows why manual scroll does not trigger the nestedscrolls.
a
You can just use
Copy code
scrollBehavior.state.apply {
    heightOffset = 0f
    contentOffset = 0f
}