is there any way of knowing the total scroll from ...
# compose
m
is there any way of knowing the total scroll from LazyListState ?
a
as in pixels-from-first-item? No, by design. The lazy layouts, like RecyclerView before it, are intended to avoid work by not measuring any content that is not currently visible or might imminently become visible. If you're 10,000 items into a social stream, measuring all of the ones above you and keeping them all composed to stay accurate in case those measurements change for some reason would be prohibitively expensive.
If you need this, use a Column with the vertical scroll modifier
m
i am talking about total scroll, not per item. I would use that to translate some view inside the LazyColumn. Currently, i’m using a workaround with firstItemOffset or sth
I am doing something like:
Copy code
graphicsLayer {
    translationY =
        if (scrollState.firstVisibleItemIndex == 0) {
            (headerHeight - toolbarHeight - scrollState.firstVisibleItemScrollOffset.toFloat())
                .coerceAtLeast(0f)
        } else 0f

    collapsingToolbar = translationY / (headerHeight - toolbarHeight)
}
which kinda works. but it wud be much easier if i had access to total scroll
thanks for your info btw 😛
r
You can't know total scroll without knowing all the item sizes that came before the first visible. If you know all of them have the same size, then you can calculate it based on position.