Hello, I’ve been playing around with lazy column a...
# compose
s
Hello, I’ve been playing around with lazy column and scroll positions. I am able to get first visible item & it’s offset … but nothing about last visible item 🤔 adding scrollable modifier throws an exception with nested scrolling not allowed 😅 any ideas how to get last visible item & offset ? Or maybe its possible to calculate by hand at least? I need to draw some shadows for toolbar and bottom bar based on scrolling
a
This solution updates the state of
lastVisibleItemIndex
when each list item is composed. I dont know, but I guess this solution is bad practice
Copy code
val state = rememberLazyListState()
val (lastVisibleItemIndex, setLastVisibleItemIndex) =
    remember(state.firstVisibleItemIndex, items) { mutableStateOf(0) }
LazyColumnForIndexed(items = items, state = state) { index, item ->
    Text("item $item")
    if (index > lastVisibleItemIndex) {
        setLastVisibleItemIndex(index)
    }
}
Text("First visible ${state.firstVisibleItemIndex}")
Text("Last visible $lastVisibleItemIndex")
s
I see… Wouldn’t it cause troubles, cause drawing each item in list updates state… which will trigger recomposition again?
a
Yeah I think so as well, but I'm still a jetpack compose noob so I haven't learned yet how recomposing really works