Is it possible to observe scroll offset? This code...
# compose
b
Is it possible to observe scroll offset? This code does not seem to work:
Copy code
val state = rememberScrollState()
LaunchedEffect(state) {
  snapshotFlow { state.value }.collect {
    Log.v(TAG, "$it") // This is never called?
  }
}
Box(Modifier.fillMaxSize().verticalScroll(state)) {
   // ... Lot of box contents
}
😢 1
a
I think it's because your box doesn't actually scroll. Try making it scrollable, e.g.
Box(Modifier.fillMaxSize().verticalScroll(state).height(1000.dp)
.
b
It does scroll, I just didn't include the content in my sample code.
a
Well I added the height modifier to your code and it does work.
z
yea that code looks right
b
Hmmm, why doesn't it work for me :(
z
Can you post more of your real code?
b
After y'all said it looked right, I looked deeper and noticed I was also using a LazyColumn deeper in the tree. The LazyColumn was doing the scrolling, so this one wasn't called. I fixed it 🙂