mattinger
04/06/2022, 10:52 PMval 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:
val isScrollingFlow = snapshotFlow { scrollState.isScrollInProgress }
var hasScrolled by remember { mutableStateOf(false) }
LaunchedEffect(key1 = true) {
isScrollingFlow.collect { isScrolling ->
if (isScrolling) {
hasScrolled = true
}
}
}