Thread
#compose
    b

    Brian G

    11 months ago
    Is it possible to observe scroll offset? This code does not seem to work:
    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
    }
    Albert Chang

    Albert Chang

    11 months ago
    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

    Brian G

    11 months ago
    It does scroll, I just didn't include the content in my sample code.
    Albert Chang

    Albert Chang

    11 months ago
    Well I added the height modifier to your code and it does work.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    11 months ago
    yea that code looks right
    b

    Brian G

    11 months ago
    Hmmm, why doesn't it work for me 😦
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    11 months ago
    Can you post more of your real code?
    b

    Brian G

    11 months ago
    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 🙂