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

Butter.Flock

02/04/2022, 11:51 AM
Hey, I have a tricky problem. I need a
Pager
in Compose that wraps its content (so the pager has the height of the largest child). I used Horizontal Pager from Accompanist, however since it is based on
LazyList
only the current item is measured and used for height calculation. If now the children have different heights this causes the content below the pager to jump around see video. So far my ideas: • Forcing the
LazyList
to measure/draw also items that are not visible (this is possible for RecyclerView), so far I could not find anything in the implementation source code to enable this behaviour. But maybe one of you has an idea? • Using
Row
instead of
LazyList
. I have an PoC for this, but it resulted in a lot of code since I had to implement Snapper for normal Rows and currently it is still a little bit buggy. I’m happy for every hint on this topic 🙂
plus1 2
c

cb

02/04/2022, 2:46 PM
What you described is pretty much expected. Pager can't wrap something which it doesn't know the height of, and a Pager could have a lot of pages in it.
b

Butter.Flock

02/04/2022, 4:24 PM
Yeah, I totally agree. However, I have only two pages. Therefore the second idea with Row + your snapper lib, I think it is doable, just a lot of code to make it work 🙂
c

Colton Idle

02/07/2022, 5:52 PM
I ended up ditching LazyRow and Pager for this. So now it looks correct, but I have lost the ability to "snap", but my designer likes it better. I am working on trying to get snap behavior, but no luck to share just yet.
c

Christoph Wiesner

04/07/2022, 7:59 AM
@Colton Idle @Butter.Flock how did you solve that problem? having same issue now
b

Butter.Flock

04/07/2022, 8:38 AM
Right now, we have a workaround. We calculate the height of the content directly. The Content contains only single line texts and paddings. Hadn’t the time to search for a better solution.
c

Christoph Wiesner

04/07/2022, 9:46 AM
ok, thanks. as my content is more diverse i cannot do that. 😕
c

Colton Idle

04/07/2022, 1:36 PM
I just used a Row with scrollable modifier
c

Christoph Wiesner

04/08/2022, 5:33 AM
did you get the snapping working in the end?
c

Colton Idle

04/08/2022, 3:22 PM
nope
28 Views