I was trying to achieve a lazy column with custom behavior. When the user pulls the lazy column after they reached the limits, I would show a refresh indicator by using the offset.
The problem is, when tested on API 29, it works as expected. onPostScroll reports the amount user scrolled even after reaching the top/bottom of the lazy column. However, it is not the case for API 33, which keeps reporting Offset(0.0,0.0) as if user did not scroll. How can I get the amount by which user scrolled?
Here is a snippet my code:
val nestedScrollConnection = remember {
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
println("PreAvailable: $available")
return super.onPreScroll(available, source)
}
override fun onPostScroll(
consumed: Offset,
available: Offset,
source: NestedScrollSource
): Offset {
println("PostAvailable: $available, consumed: $consumed")
return super.onPostScroll(consumed, available, source)
}
}
}
Box (
modifier = Modifier.nestedScroll(nestedScrollConnection)
) {
LazyColumn(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(count = 100) {
Text(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.background(Color.Blue)
.padding(vertical = 12.dp),
text = "Item $it",
color = Color.White,
textAlign = TextAlign.Center
)
}
}
}
Farid Guliyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.