compose-collapsing-toolbar icon indicating copy to clipboard operation
compose-collapsing-toolbar copied to clipboard

Not collapsing when using LazyListState.animateScrollToItem

Open antoine-purnelle-lb opened this issue 3 years ago • 8 comments

Hi

when running this code, where state is the LazyListState of the LazyColumn which is the body, the CollapsingToolbarScaffold doesn't collapse and the LazyColumn scrolls behind it.

Thanks for the help

coroutineScope.launch {
  delay(500)
  state.animateScrollToItem(issue.comments.size - 1)
}

antoine-purnelle-lb avatar Jun 08 '21 14:06 antoine-purnelle-lb

I am looking at the implementation of LazyList, though I'm not sure what is going on exactly, it seems that animateScrollToItem() does not dispatch nested scroll. If this is true, then there is barely nothing my code can do to fix it for now. I will try to investigate what is going on and notify you when I find something :)

onebone avatar Jun 16 '21 08:06 onebone

Thanks @onebone !

antoine-purnelle-lb avatar Jun 16 '21 09:06 antoine-purnelle-lb

@antoine-purnelle-lb wanna file a bug report with jetpack compose?

saket avatar Oct 20 '21 19:10 saket

Any update on this issue? acing the same issue or any work around

aniluMango avatar Jan 10 '23 05:01 aniluMango

Any update on this issue? acing the same issue or any work around

I think we should manually expand or collapse the toolbar. Given animateScrollToItem() and expand()/collapse() is a suspending function, it should be easy to do it.

onebone avatar Jan 18 '23 14:01 onebone

@onebone I have tried to collapse() manually but it does not work. I have the following code

val rememberCollapsingToolbarScaffoldState = rememberCollapsingToolbarScaffoldState()

in suspend block call following

rememberCollapsingToolbarScaffoldState.toolbarState.collapse(100)

any thing wrong with it? thanks in advance

aniluMango avatar Jan 19 '23 05:01 aniluMango

@aniluMango Sorry for the late response, I see no problems in your given code. Maybe there some are reason if it does not work? The following is my tested code, which collapses the toolbar and scrolls a lazy list to index 5.

Button(
  onClick = {
    scope.launch {
      state.toolbarState.collapse()
      listState.animateScrollToItem(5)
    }
  }
) {
  Text(text = "Floating Button!")
}

onebone avatar Feb 12 '23 13:02 onebone

Is there no notify or invalidate method we could use on the toolbarState so that it calculates itself if it has to collapse or not?

oldergod avatar Jun 13 '24 13:06 oldergod