Zoltan Demant
09/07/2021, 4:16 AMLazyListState
(scroll position) between multiple LazyRow
? Ive tried using one rememberLazyListState
but that results in weird scrolling glitches; Im sort of assuming that Ill need to collect all scroll events and update each LazyListState
?cb
09/08/2021, 7:02 AMLazyListState
contains all of the layout state for its host component, so it can only really be used in a single LazyColumn
, etc.
I wouldn’t mess around with touch input here. I’d use a LaunchedEffect
to read the first visible item + offset on each LazyListState
, then call scrollToItem
to coordinate the others.
You might need to gate the changes on isScrollInProgress
to stop any recursion loops.Zoltan Demant
09/08/2021, 11:05 AMZoltan Demant
09/08/2021, 2:37 PMval listControllers = remember {
mutableStateMapOf<ChartType, ListController>()
}
LaunchedEffect(listControllers) {
val controllers = listControllers.values
snapshotFlow {
controllers
.firstOrNull(ListController::scrollInProgress)
?.let { controller ->
val index = controller.firstVisibleItemIndex()
val scrollOffset = controller.firstVisibleItemScrollOffset()
index to scrollOffset
}
}
.filterNotNull()
.distinctUntilChanged()
.collect { (index, scrollOffset) ->
controllers.forEach { controller ->
if (!controller.scrollInProgress()) {
controller.scrollTo(
index,
scrollOffset
)
}
}
}
}
cb
09/08/2021, 6:04 PMcb
09/08/2021, 6:05 PM