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

Chris Johnson

07/08/2021, 4:24 PM
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

tad

07/08/2021, 4:39 PM
localBoundingBoxOf(parentLayoutCoordinates)
in
onGloballyPositioned
But needing this info is a little smelly, what's the use case?
1
c

Chris Johnson

07/08/2021, 5:32 PM
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

tad

07/08/2021, 5:37 PM
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

Chris Johnson

07/08/2021, 5:47 PM
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

tad

07/08/2021, 5:49 PM
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

Chris Johnson

07/08/2021, 5:50 PM
Good idea. I'll mull that one over and see if I can get it working how I need it : )
t

tad

07/08/2021, 5:51 PM
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

Chris Johnson

07/08/2021, 6:06 PM
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

tad

07/08/2021, 6:07 PM
those are some pretty detailed analytics!
c

Chris Johnson

07/08/2021, 6:07 PM
sadly. Yes. 😭
7 Views