1

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
                    )
                }
            }
        }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.