Is there an equivalent to `view.getLocalVisibleRec...
# compose
c
Is there an equivalent to
view.getLocalVisibleRect(rect)
in compose? Also, is there another way to get the rect of a compose view without using
onGloballyPositioned
from the modifier?
t
localBoundingBoxOf(parentLayoutCoordinates)
in
onGloballyPositioned
But needing this info is a little smelly, what's the use case?
1
c
The smelliest of requirements. Analytics. The reason I don't really wanna use
onGloballyPositioned
is because this needs to go in a list and that gets called an insane amount of times. I could maybe add a flag that after the first calculation to not add it to the modifier but I was hoping for a better way 😞
Also thanks I'll look into
localBoundingBoxOf
t
If this is in a
LazyColumn
you can use
LazyListState
to get the list of visible items
and get layout info for each one
c
Right, but as an item is scrolled to be visible I'm looking to track that. I have requirements that sort of need pixel information via Rects. Mostly I was trying to see if there was an equivalent to those 2 things from the view system.
t
Yeah, you can use
snapshotFlow { lazyListState.layoutInfo }
and some Flow operators to grab which items come into view, and their pixel offsets
👍 1
Wrapped up in a
LaunchedEffect
of course
💯 1
c
Good idea. I'll mull that one over and see if I can get it working how I need it : )
t
Oh, something very similar to that is
AnimatedItem
from one of the compose samples, lemme dig it up
like, there's a boolean state (
visible
) that's changed when each item comes into view
should be adaptable to your use case
c
haha I actually used this sample to come up with animations for animating items in/out of my list. I might be able to do something with
LazyListState
although I fear I'm going to need more detailed information.
t
those are some pretty detailed analytics!
c
sadly. Yes. 😭