Thread
#compose
    Chris Johnson

    Chris Johnson

    1 year ago
    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

    1 year ago
    localBoundingBoxOf(parentLayoutCoordinates)
    in
    onGloballyPositioned
    But needing this info is a little smelly, what's the use case?
    Chris Johnson

    Chris Johnson

    1 year ago
    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

    1 year ago
    If this is in a
    LazyColumn
    you can use
    LazyListState
    to get the list of visible items
    and get layout info for each one
    Chris Johnson

    Chris Johnson

    1 year ago
    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

    1 year ago
    Yeah, you can use
    snapshotFlow { lazyListState.layoutInfo }
    and some Flow operators to grab which items come into view, and their pixel offsets
    Wrapped up in a
    LaunchedEffect
    of course
    Chris Johnson

    Chris Johnson

    1 year ago
    Good idea. I'll mull that one over and see if I can get it working how I need it : )
    t

    tad

    1 year ago
    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
    Chris Johnson

    Chris Johnson

    1 year ago
    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

    1 year ago
    those are some pretty detailed analytics!
    Chris Johnson

    Chris Johnson

    1 year ago
    sadly. Yes. 😭