Hi, I am using a custom Horizontal Pager made wit...
# compose
a
Hi, I am using a custom Horizontal Pager made with
Layout
with custom draggable and state handling. I am facing problem with Pager height. If I give specific height, then it works fine. But if I don’t give any height and use
Modifier.wrapContentHeight()
then Pager does not show up. The items may have different heights that is why wrapContentHeight is must. I have tried to debug it and found out that, when no height is given then Constraints in
Layout
have height set to zero hence placeables get zero height. Kindly help. Code attached in the thread.
s
You have to pass
layout
a
height
somehow, e.g. the max measured height of
placeables
k
Keep this to the thread please instead of sending everything to the channel.
s
you can to do something like this:
Copy code
{ measurables, constraints ->
  val placeables = measurables.map { it.measure(contraints) }
  val maxHeight = placeables.maxOf { it.height }
  layout(contraints.maxWidth, maxHeight) { ... }
}
However I think you should measure your measurables like this (i.e. set
minWidth
or
minHeight
to zero according to the orientation):
Copy code
when (orientation) {
    Orientation.Vertical -> measure(it, constraints.copy(minWidth = 0))
    Orientation.Horizontal -> measure(it, constraints.copy(minHeight = 0))
}
a
Pager has only Horizontal orientation. However, I have already tried setting minHeight to zero but no luck.
a
do you have a complete code and what PagerState as a class is trying to build a custom pager with some offset animations but stuck with dealing with layout
231 Views