# compose

Rick Regan

02/09/2021, 12:27 AM
Is there a way to get a callback when a user scrolls a scrollable
? (I'm using
on the Text, and the text has
maxLines = 1
.) I was looking for it in
but it looks like that's just used to programatically scroll. I'd like to use the scroll as a trigger to generate more characters of text; for example, more decimal places of a given number. (I guess this is kind of a "lazy" or "pagination" like behavior for Text.)


02/09/2021, 8:59 AM
Does ScrollState have a scroll position variable in it? If so you can create a snapshotFlow out of it and then observe/collect it.

Rick Regan

02/09/2021, 3:19 PM
It does expose the scroll position. Thanks for the suggestion. I found limited documentation on snapshotFlow so I have to dig into that more. But I found examples of Kotlin flow and made something out of that. I emit the scroll position after a short delay (I need to make it responsive, for if and when the user starts scrolling). Should I be concerned about the rate of polling? I think I'll also I have to work in some tolerance for the float value before I consider it changed and emit it. And there are probably several other issues I'd have to work through to make it robust. Maybe snapshotFlow makes this better (or does it just hide it better?) A callback from scrollState would really have been preferable. Of course even then I'd probably need some mechanism to measure text in order to scroll the right amount.