I'm currently working with Compose Desktop and utilizing a LazyRow in my layout. I have a requirement to retrieve the positions in the root coordinate space for the following:

  • First Item
  • Last Item
  • First Visible Item
  • Last Visible Item

While I'm aware that the onGloballyPositioned modifier can be used to obtain positions, I'm concerned about performance implications, especially when dealing with a large number of items. Iterating through every item to check its position using onGloballyPositioned seems suboptimal.

Could someone suggest an efficient approach or method to retrieve the positions of the first, last, first visible, and last visible items in a LazyRow without the need to iterate through each item individually?

LazyRow {
items( /* your items here */) { item ->
    // item content
    // ...
    // onGloballyPositioned { /* handling position */ }
    }
}

Additional Context:

I'm using Compose version 1.5.3. The number of items in the LazyRow can vary, and performance optimization is crucial. Any guidance or sample code for achieving this efficiently would be highly appreciated.

0

There are 0 answers