Layout hierarchy:
I have a fragment-based bottom sheet with a custom behavior. I need the root composable to be a LazyColumn to properly handle nested scrolling with the bottom sheet.
Then I have a sticky header, non sticky composables, and a (compose) pager. The pager has a (longish) list in the first page.
Problems I face:
As far as I know there's no way of having a LazyColumn inside of another LazyColumn, currently. I am using a simple column which has two issues.
• Performance, as it keeps all list items in composition. As the list is longer than what fits in the screen but no more than about twice the screen height, it is not currently a big concern.
• I need to scroll to a specific item of the inner list, and I think there is no API for that. This is the main issue.
Explorations:
1. I've read how animateScrollToItem works in LazyColumn and I wanted to replicate it for my case. The problem is that I do not know how can I see which item is the first visible item in the (inner) list.
To know whether the target item is visible I was thinking about using onGloballyPositioned but I don't think it'll be reliable. I am not sure, but I expect the onGloballyPositioned to be called after the scroll takes place, so it will always be at least a frame old. Therefore, I do not know how to do this, if it is even possible...
2. Another possibility is not using a real pager -just the tabs-, and having all composables as items of the parent LazyColumn. But here I think I'd have to sacrifice switching tabs with horizontal scroll, and animating the change of tabs (horizontal animation of the list items). Is there a way of treating some list items as a whole and animating them together when they change?
3. What I intend to do if I don't find a better approach: as all items are of similar height, I can compute the average height of an item, estimate where the item should be based on position in the whole list, and scroll so that it ends up in the middle of the screen instead of the top. It would be preferable at the top, but as the estimation will be unaccurate at the middle the lack of precision will be less of an issue.
Questions:
• Is there a way of having nested LazyColumns of of properly scrolling in case 1?
• Is there a way of treating several list items as a group, as in case 2?
• Any alternative that I missed?