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

Roar Gronmo

12/07/2019, 3:46 PM
VerticalScroller onScrollPositionChanged which was available in dev02 has disappeared in dev03. Do any have any clues how to read the VerticalScrollers postion now, or do we use another method to register scrollingchanges ?
a

Adam Powell

12/07/2019, 5:05 PM
Use the
ScrollerPosition
hoisted state object, its
value
property is backed by
@Model
and reading it will trigger recomposition as needed
note, this sample will be very slow right now but it will demonstrate 🙂
Copy code
Column {
    val pos = +memo { ScrollerPosition() }
    Text("position: ${pos.value}")
    VerticalScroller(pos) {
        // content
(note: slow because it recomposes both the text and scroller per frame there and there's still a bunch of missing optimizations in this path; if you stick the text in a fixed size container it's much less so)
r

Roar Gronmo

12/08/2019, 8:32 AM
Thanx @Adam Powell, do you know if there will be an "onEdgeOfList" trigger function (with some sort of displacement) to trigger loading of new elements in to the list in the future?
a

Adam Powell

12/08/2019, 2:24 PM
Probably not in
VerticalScroller
as it's meant to be the
ScrollView
analog for smaller/less dynamic content. The `ListView`/`RecyclerView` analog is WIP at the moment and definitely will.
But if you're looking for a way to do it with
VerticalScroller
today, you should have everything you need. Something like
Copy code
val ScrollerPosition.isAtEndOfList: Boolean get() = value >= maxPosition - range
should do the trick
and then using the usual model observation described above
VerticalScroller
composes its entire content body though, and given that you're also asking questions about integrating with database queries it's not intended to be the heavily scalable component for this sort of thing 🙂