https://kotlinlang.org logo
#compose
Title
# compose
s

Stylianos Gakis

02/17/2023, 1:44 PM
I have 1 lazy list atm, but wanted to have 2 lists side by side, one being a bit different than the other. To make it simple for myself I figured let’s try doing smth like this:
Copy code
Row {
  val lazyGridState = rememberLazyGridState()
  LazyVerticalGrid(lazyGridState)
  LazyVerticalGrid(lazyGridState)
}
In hopes that maybe those two can share the scroll state and scroll together. What I did end up with instead, is that the second lazy layout works and scrolls correctly. And the first one, when I scroll there, it also moves the scroll position of the second call. Clearly indicating I am not supposed to be doing that 😅 My second option now is to edit the
item{}
provided to the grid itself, keeping 1 lazy grid only and simply make each item show twice side by side to emulate what I was going for here. Now my question is, is there some way my original idea can actually be used? Are the Lazy*State objects simply not built to be able to support being passed to two layouts at the same time?
z

Zoltan Demant

02/17/2023, 2:36 PM
Fwiw, I did the same thing with two LazyColumns in the past, it worked equally bad. Maybe my workaround applies to your situation as well - I just ended up having two lazyListStates that would inform each other of their scroll events, and then sync up that way. I dont have the code anymore, but iirc, there was some logic that would stop them from informing each other at the same time as well so that only one list would "control" the other(s).
s

Stylianos Gakis

02/17/2023, 3:05 PM
Yeah that might be something that I try if I don’t go with the other approach
6 Views