Does anyone know if there’s some kind of folding f...
# compose
m
Does anyone know if there’s some kind of folding function for derived state that gives you the previous value in order to compute your calculation? Something like this:
Copy code
val foldedDerivedState = derivedStateOf(initialValue=0) { accumulator ->
    // do some calculation with other state and the accumulator.
}
I’m basically working on something that’s tracking scrolling state over time, and need a boolean to determine if the user has EVER scrolled the column. I can do this with a ScrollState, but it’s ugly and requires a snapshotFlow and a LaunchedEffect to collect it:
Copy code
val isScrollingFlow = snapshotFlow { scrollState.isScrollInProgress }
var hasScrolled by remember { mutableStateOf(false) }
LaunchedEffect(key1 = true) {
    isScrollingFlow.collect { isScrolling ->
        if (isScrolling) {
            hasScrolled = true
        }
    }
}