KamilH
02/21/2023, 5:47 AMLazyColumn
, which contains multiple `LazyRow`s scrolled together. The idea is to apply a horizontal scrollable
Modifier on a LazyColumn
, get scrolled delta, and manually scrollBy
all the rows (code in thread). This works correctly when I’m scrolling up-down slowly, but it breaks on faster scrolls. I thought some synchronization mechanism was needed here; however, implementing it didn’t help. Do you see how I can improve it? Or why does it happen?TwoWayScrollableList(
rowItems = (0..10).map { it.toString() },
listSize = 100,
)
@Composable
fun TwoWayScrollableList(
rowItems: List<String>,
listSize: Int,
) {
val states = (0..listSize).map { rememberLazyListState() }
val scope = rememberCoroutineScope()
val scrollState = rememberScrollableState { delta ->
scope.launch {
states.forEach {
it.scrollBy(-delta)
}
}
delta
}
LazyColumn(
modifier = Modifier.scrollable(scrollState, Orientation.Horizontal, flingBehavior = ScrollableDefaults.flingBehavior())
) {
itemsIndexed(items = states) { _, item ->
LazyRow(
state = item,
userScrollEnabled = false,
) {
itemsIndexed(items = rowItems) { _, item ->
Text(
text = item,
textAlign = TextAlign.Center,
fontSize = 25.sp,
modifier = Modifier.width(100.dp).background(color = Color.Gray)
)
}
}
Spacer(modifier = Modifier.height(2.dp))
}
}
}
Altynbek Nurtaza
02/21/2023, 9:59 AMKamilH
02/21/2023, 11:12 AMLazyRow
. Also, I would like to get stickyHeader
easily.
I discovered that because Lazy
is reusing containers, I can reuse LazyListState
as well; however, I need to find a way how to implement it the nice way because, for now, it’s somewhat hacky. 😄