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

Ilias Zosimadis

02/13/2021, 11:48 AM
Hi all! Is it possible to consume the scroll delta offset of a LazyRow? I think I can't just use the ScrollableController modifier.
👌 1
j

Julien Salvi

02/13/2021, 12:13 PM
Check the LazyScrollState attribute of the Composable ;)
i

Ilias Zosimadis

02/13/2021, 3:33 PM
You mean the
LazyListState
? In this case, the onScroll function is internal and we don't have access to the consumed distance. Also the
firstVisibleItemScrollOffset
is the offset of the first item.
s

Shakil Karim

02/13/2021, 3:53 PM
You can use
firstVisibleItemScrollOffset
for getting offset like this
Copy code
val collapseRange = with(AmbientDensity.current) { (TopItemHeight).toPx() }
val collapseFraction =
    (scrollState.firstVisibleItemScrollOffset / collapseRange).coerceIn(0f, 1f)
👍 1
But you have to check if Item is first one because it reset after each item scrollState.firstVisibleItemIndex > 0
👍 2
i

Ilias Zosimadis

02/13/2021, 4:11 PM
Yes, I made a similar solution with
firstVisibleItemScrollOffset
but I think it would be much simpler if we had access to the
onScroll
function.
j

Julien Salvi

02/13/2021, 4:15 PM
Yep I was thinking the solution as Shakil because unfortunately there is no global scroll offset available for LazyRow or LazyColumn
1
4 Views