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

Justin Xu

02/23/2023, 12:49 AM
I have a
LazyColumn
displaying my UI elements, and sometimes the contents don't fill one entire screen. How would I detect if there is empty space and the size of that space between the last
item
and the bottom of the screen
e

ephemient

02/23/2023, 4:04 AM
something like
Copy code
val listState = rememberLazyListState()
LazyColumn(state = listState) {
    // ...
}
val startEndSpace by snapshotFlow {
    with(listState.layoutInfo) {
        visibleItemsInfo.firstOrNull()?.takeIf { it.index == 0 }?.let { it.offset - viewportStartOffset } to
            visibleItemsInfo.lastOrNull()?.takeIf { it.index == totalItemsCount - 1 }?.let {
                viewportEndOffset - (it.offset + it.size)
            }
    }
}.collectAsState(initial = null to null)
10 Views