I am trying to observe the total scrollY of a nest...
# compose
a
I am trying to observe the total scrollY of a nested scroll connection, but the results are wrong for fast scrolls, code in 🧵
Copy code
.nestedScroll(object : NestedScrollConnection {
  override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
    scrollY += available.y
    return super.onPreScroll(available, source)
  }
}
I am trying to measure how far views in the hierarchy have scrolled, regardless of if the descendants are a LazyColumn or a scrollable Column for example. I did the naive approach of just summing up all scroll events in a NestedScrollConnection as seen above. This works well for slow deliberate scrolling, but as soon as I do fast scrolling in both directions (kind of stress testing this implementation) the resulting scrollY gets out of sync with the observed scroll that is on the screen. Can anyone point me in the right direction on how to properly observe child scrolling in jetpack compose without relying on the specific scrollState of the children (since for all I know the children might do their own nested scrolling magic anyhow)?
s
were you able to find an answer? and what version of compose are you using?
a
i think it stemmed from the fact that i did not overwrite onfling, it seems that its completely on you to handle flinging should you do any scroll observation, which is unfortunate
s
Are you sure? I checked that my
onScroll()
callback was getting called during flings. I investigated my code a bit more and I may have found my issue -- LazyColumn has items that change height causing the scroll offset to go out of sync.
a
Pretty sure.. or I might have discovered a bug? It seems like the overscroll effect of scrollable columns comsumes all flings. Not completely sure, but a naive implementation (as above) does not work smoothely for me for sure.
124 Views