https://kotlinlang.org logo
#compose
Title
# compose
z

Zoltan Demant

11/27/2023, 8:18 AM
Has anyone had any success with scrolling to a
LazyColumn
item inside a
ModalBottomSheet
? I just find that nothing happens, and I think its because of the sheets half expanded state.
x

xoangon

11/27/2023, 8:23 PM
I've been recently fighting with setting scroll state.
LazyListState::scrollToItem
wasn't performing a scroll at all in my case, while
LazyListState::animateScrollToItem
did the work. I guess there's some race condition to update the UI, but I've found no way to make
scrollToItem
work. Does
animateScrollToItem
work for you? It's not the greatest UX approach, as I'd rather the scroll to be invisible to the user
z

Zoltan Demant

11/28/2023, 5:44 AM
Have you tried specifying the initial index directly when calling
rememberLazyListState
? Might be worth filing a bug in either case though! I suspect my case is odd because effectively the list scroll would need to trigger the sheet to move up the screen (like when dragging it up to see more items) which I dont think it can do at this point.
LazyListState::animateScrollToItem
didnt make any difference here. Furthermore, if I populate my list with more items, it kind of scrolls .. just not far enough to make the specified index actually visible.
x

xoangon

11/28/2023, 1:04 PM
In my case I'm not using
rememberLazyListState
, I'm creating the state out of the Compose world, hoisting it to an state holder. I'm taking care of notifying Compose of state changes but still
LazyListState::scrollToItem
doesn't do the job in my case 😕 I'll see if there's any reports and open one if not. You seem to even be in a worse place than mine with none of the
LazyListState
functions doing the job 😵‍💫
z

Zoltan Demant

11/28/2023, 1:32 PM
I chose to create a ticket for my issue here, added some more details in there too! 😃 For your case, are you able to test having the list state be part of "the compose world" and checking if it scrolls to the item then? Just to make sure none of the custom stuff is getting in the way!
❤️ 1
x

xoangon

11/28/2023, 1:40 PM
Great point! In fact, now that you say it, I do remember using
rememberLazyListState
as part of my debugging process to see if the error was caused by my implementation. The result was the same, though 🥲
z

Zoltan Demant

11/28/2023, 1:43 PM
Gotcha! 😞 Sounds like a good case for an issue, give me a poke if/when you create one and Ill star it!
7 Views