How do you set the maximum value for a manually-co...
# compose
o
How do you set the maximum value for a manually-controlled scroll? I can’t set the
maxValue
on
ScrollState
because it’s internal… I’m using
verticalScroll
modifier on my component, but can’t figure out how to set its limits…
@Adam Powell sorry for mention, but I’m asking this for a second time already I think and have no idea how to progress…
a
@matvei for next week
m
Hm, could you share what are you trying to achieve? Modifiers like
Modifier.verticalScroll
or
Modifier.horizontalScroll
are autonomous in this regard as they will measure your @Composable you are applying them to and get the max height from it. Hence
state.maxHeight
is a read only val. So the bounds are the natural 0 and height of a composable, assuming the composable is bigger then its viewport. If you want something more custom and want to have more control over the scroll and how to interpret it, you could try using
Modifier.scrollable
, which provides scroll handling but not layout, allowing you to write more custom things
o
@matvei It’s a SnakeLayout component, which is kinda like grid (fixed size cells), but odd and even rows are in opposite directions 🙂 It’s basically a
Layout
with
verticalScroll
, and pretty trivial placing. I’ll send gist in DM.
The problem was that
layout
was called with
layout(constraints.maxWidth, constraints.maxHeight)
, which is essentially “infinite” vertically. I had to rewrite the component’s logic to first calculate item placements, then infer maxHeight from there, and then call layout with proper height.
🎉 1